Mercurial > prosody-hg
comparison plugins/muc/muc.lib.lua @ 7706:d92e186c2a1c
MUC: Include the appropriate status code if nickname is changed during join process
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 26 Oct 2016 13:10:22 +0200 |
| parents | 0a29a5e64f1d |
| children | 47cb54a08336 |
comparison
equal
deleted
inserted
replaced
| 7705:0a29a5e64f1d | 7706:d92e186c2a1c |
|---|---|
| 400 -- TODO Handle this case sensibly | 400 -- TODO Handle this case sensibly |
| 401 if not stanza:get_child("x", "http://jabber.org/protocol/muc") then | 401 if not stanza:get_child("x", "http://jabber.org/protocol/muc") then |
| 402 module:log("debug", "Room creation without <x>, possibly desynced"); | 402 module:log("debug", "Room creation without <x>, possibly desynced"); |
| 403 end | 403 end |
| 404 | 404 |
| 405 local orig_nick = dest_occupant.nick; | |
| 405 if module:fire_event("muc-occupant-pre-join", { | 406 if module:fire_event("muc-occupant-pre-join", { |
| 406 room = self; | 407 room = self; |
| 407 origin = origin; | 408 origin = origin; |
| 408 stanza = stanza; | 409 stanza = stanza; |
| 409 is_first_session = is_first_dest_session; | 410 is_first_session = is_first_dest_session; |
| 410 is_new_room = true; | 411 is_new_room = true; |
| 411 occupant = dest_occupant; | 412 occupant = dest_occupant; |
| 412 }) then return true; end | 413 }) then return true; end |
| 414 local nick_changed = orig_nick ~= dest_occupant.nick; | |
| 413 | 415 |
| 414 dest_occupant:set_session(real_jid, stanza); | 416 dest_occupant:set_session(real_jid, stanza); |
| 415 local dest_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); | 417 local dest_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
| 416 dest_x:tag("status", {code = "201"}):up(); | 418 dest_x:tag("status", {code = "201"}):up(); |
| 417 if self:get_whois() == "anyone" then | 419 if self:get_whois() == "anyone" then |
| 418 dest_x:tag("status", {code = "100"}):up(); | 420 dest_x:tag("status", {code = "100"}):up(); |
| 419 end | 421 end |
| 422 local self_x; | |
| 423 if nick_changed then | |
| 424 self_x = st.clone(dest_x); | |
| 425 self_x:tag("status", {code = "210"}):up(); | |
| 426 end | |
| 420 self:save_occupant(dest_occupant); | 427 self:save_occupant(dest_occupant); |
| 421 | 428 |
| 422 self:publicise_occupant_status(dest_occupant, dest_x); | 429 self:publicise_occupant_status(dest_occupant, {base = dest_x, self = self_x}); |
| 423 | 430 |
| 424 module:fire_event("muc-occupant-joined", { | 431 module:fire_event("muc-occupant-joined", { |
| 425 room = self; | 432 room = self; |
| 426 nick = dest_occupant.nick; | 433 nick = dest_occupant.nick; |
| 427 occupant = dest_occupant; | 434 occupant = dest_occupant; |
| 483 module:log("debug", "Join without <x>, possibly desynced"); | 490 module:log("debug", "Join without <x>, possibly desynced"); |
| 484 elseif orig_occupant ~= nil and muc_x then | 491 elseif orig_occupant ~= nil and muc_x then |
| 485 module:log("debug", "Presence update with <x>, possibly desynced"); | 492 module:log("debug", "Presence update with <x>, possibly desynced"); |
| 486 end | 493 end |
| 487 | 494 |
| 495 local orig_nick = dest_occupant and dest_occupant.nick; | |
| 496 | |
| 488 local event, event_name = { | 497 local event, event_name = { |
| 489 room = self; | 498 room = self; |
| 490 origin = origin; | 499 origin = origin; |
| 491 stanza = stanza; | 500 stanza = stanza; |
| 492 is_first_session = is_first_dest_session; | 501 is_first_session = is_first_dest_session; |
| 503 event.orig_occupant = orig_occupant; | 512 event.orig_occupant = orig_occupant; |
| 504 event.dest_occupant = dest_occupant; | 513 event.dest_occupant = dest_occupant; |
| 505 end | 514 end |
| 506 if module:fire_event(event_name, event) then return true; end | 515 if module:fire_event(event_name, event) then return true; end |
| 507 | 516 |
| 517 local nick_changed = dest_occupant and orig_nick ~= dest_occupant.nick; | |
| 518 | |
| 508 -- Check for nick conflicts | 519 -- Check for nick conflicts |
| 509 if dest_occupant ~= nil and not is_first_dest_session and bare_jid ~= jid_bare(dest_occupant.bare_jid) then -- new nick or has different bare real jid | 520 if dest_occupant ~= nil and not is_first_dest_session and bare_jid ~= jid_bare(dest_occupant.bare_jid) then -- new nick or has different bare real jid |
| 510 log("debug", "%s couldn't join due to nick conflict: %s", real_jid, dest_occupant.nick); | 521 log("debug", "%s couldn't join due to nick conflict: %s", real_jid, dest_occupant.nick); |
| 511 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); | 522 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); |
| 512 reply.tags[1].attr.code = "409"; | 523 reply.tags[1].attr.code = "409"; |
| 584 self:send_occupant_list(real_jid, function(nick, occupant) -- luacheck: ignore 212 | 595 self:send_occupant_list(real_jid, function(nick, occupant) -- luacheck: ignore 212 |
| 585 -- Don't include self | 596 -- Don't include self |
| 586 return occupant:get_presence(real_jid) == nil; | 597 return occupant:get_presence(real_jid) == nil; |
| 587 end) | 598 end) |
| 588 end | 599 end |
| 589 self:publicise_occupant_status(dest_occupant, dest_x); | 600 local self_x; |
| 601 if nick_changed then | |
| 602 self_x = st.clone(dest_x); | |
| 603 self_x:tag("status", {code="210"}):up(); | |
| 604 end | |
| 605 self:publicise_occupant_status(dest_occupant, {base=dest_x,self=self_x}); | |
| 590 | 606 |
| 591 if orig_occupant ~= nil and orig_occupant ~= dest_occupant and not is_last_orig_session then -- If user is swapping and wasn't last original session | 607 if orig_occupant ~= nil and orig_occupant ~= dest_occupant and not is_last_orig_session then -- If user is swapping and wasn't last original session |
| 592 log("debug", "session %s split nicks; showing %s rejoining", real_jid, orig_occupant.nick); | 608 log("debug", "session %s split nicks; showing %s rejoining", real_jid, orig_occupant.nick); |
| 593 -- Show the original nick joining again | 609 -- Show the original nick joining again |
| 594 local pr = st.clone(orig_occupant:get_presence()); | 610 local pr = st.clone(orig_occupant:get_presence()); |
