390 if text and self:get_whois() == "anyone" then |
390 if text and self:get_whois() == "anyone" then |
391 error_message = error_message..": "..text; |
391 error_message = error_message..": "..text; |
392 end |
392 end |
393 occupant:set_session(real_jid, st.presence({type="unavailable"}) |
393 occupant:set_session(real_jid, st.presence({type="unavailable"}) |
394 :tag('status'):text(error_message)); |
394 :tag('status'):text(error_message)); |
|
395 local orig_role = occupant.role; |
395 local is_last_session = occupant.jid == real_jid; |
396 local is_last_session = occupant.jid == real_jid; |
396 if is_last_session then |
397 if is_last_session then |
397 occupant.role = nil; |
398 occupant.role = nil; |
398 end |
399 end |
399 local new_occupant = self:save_occupant(occupant); |
400 local new_occupant = self:save_occupant(occupant); |
400 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
401 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
401 if is_last_session then |
402 if is_last_session then |
402 x:tag("status", {code = "333"}); |
403 x:tag("status", {code = "333"}); |
403 end |
404 end |
404 self:publicise_occupant_status(new_occupant or occupant, x); |
405 self:publicise_occupant_status(new_occupant or occupant, x, nil, nil, nil, orig_role); |
405 if is_last_session then |
406 if is_last_session then |
406 module:fire_event("muc-occupant-left", { |
407 module:fire_event("muc-occupant-left", { |
407 room = self; |
408 room = self; |
408 nick = occupant.nick; |
409 nick = occupant.nick; |
409 occupant = occupant; |
410 occupant = occupant; |
603 end |
604 end |
604 |
605 |
605 -- Send presence stanza about original occupant |
606 -- Send presence stanza about original occupant |
606 if orig_occupant ~= nil and orig_occupant ~= dest_occupant then |
607 if orig_occupant ~= nil and orig_occupant ~= dest_occupant then |
607 local orig_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
608 local orig_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
|
609 local orig_role = orig_occupant.role; |
608 local dest_nick; |
610 local dest_nick; |
609 if dest_occupant == nil then -- Session is leaving |
611 if dest_occupant == nil then -- Session is leaving |
610 log("debug", "session %s is leaving occupant %s", real_jid, orig_occupant.nick); |
612 log("debug", "session %s is leaving occupant %s", real_jid, orig_occupant.nick); |
611 if is_last_orig_session then |
613 if is_last_orig_session then |
612 orig_occupant.role = nil; |
614 orig_occupant.role = nil; |
645 dest_nick = nil; -- set dest_nick to nil; so general populace doesn't see it for whole orig_occupant |
647 dest_nick = nil; -- set dest_nick to nil; so general populace doesn't see it for whole orig_occupant |
646 end |
648 end |
647 end |
649 end |
648 |
650 |
649 self:save_occupant(orig_occupant); |
651 self:save_occupant(orig_occupant); |
650 self:publicise_occupant_status(orig_occupant, orig_x, dest_nick); |
652 self:publicise_occupant_status(orig_occupant, orig_x, dest_nick, nil, nil, orig_role); |
651 |
653 |
652 if is_last_orig_session then |
654 if is_last_orig_session then |
653 module:fire_event("muc-occupant-left", { |
655 module:fire_event("muc-occupant-left", { |
654 room = self; |
656 room = self; |
655 nick = orig_occupant.nick; |
657 nick = orig_occupant.nick; |
677 self_x:tag("status", {code = "100"}):up(); |
679 self_x:tag("status", {code = "100"}):up(); |
678 end |
680 end |
679 if nick_changed then |
681 if nick_changed then |
680 self_x:tag("status", {code="210"}):up(); |
682 self_x:tag("status", {code="210"}):up(); |
681 end |
683 end |
682 self:publicise_occupant_status(dest_occupant, {base=dest_x,self=self_x}); |
684 self:publicise_occupant_status(dest_occupant, {base=dest_x,self=self_x}, nil, nil, nil, orig_occupant and orig_occupant.role or nil); |
683 |
685 |
684 if orig_occupant ~= nil and orig_occupant ~= dest_occupant and not is_last_orig_session then |
686 if orig_occupant ~= nil and orig_occupant ~= dest_occupant and not is_last_orig_session then |
685 -- If user is swapping and wasn't last original session |
687 -- If user is swapping and wasn't last original session |
686 log("debug", "session %s split nicks; showing %s rejoining", real_jid, orig_occupant.nick); |
688 log("debug", "session %s split nicks; showing %s rejoining", real_jid, orig_occupant.nick); |
687 -- Show the original nick joining again |
689 -- Show the original nick joining again |
1360 end |
1362 end |
1361 local is_semi_anonymous = self:get_whois() == "moderators"; |
1363 local is_semi_anonymous = self:get_whois() == "moderators"; |
1362 |
1364 |
1363 if next(occupants_updated) ~= nil then |
1365 if next(occupants_updated) ~= nil then |
1364 for occupant, old_role in pairs(occupants_updated) do |
1366 for occupant, old_role in pairs(occupants_updated) do |
1365 self:publicise_occupant_status(occupant, x, nil, actor, reason); |
1367 self:publicise_occupant_status(occupant, x, nil, actor, reason, old_role); |
1366 if occupant.role == nil then |
1368 if occupant.role == nil then |
1367 module:fire_event("muc-occupant-left", { |
1369 module:fire_event("muc-occupant-left", { |
1368 room = self; |
1370 room = self; |
1369 nick = occupant.nick; |
1371 nick = occupant.nick; |
1370 occupant = occupant; |
1372 occupant = occupant; |