Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 7667:5523880760b3
MUC: Insert the appropriate status code (210) if the nickname is overridden
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 29 Sep 2016 22:04:59 +0200 |
parent | 7661:37ab6c6326fe |
child | 7668:96c6c25a51e1 |
comparison
equal
deleted
inserted
replaced
7666:03aa330562ed | 7667:5523880760b3 |
---|---|
489 origin = origin; | 489 origin = origin; |
490 stanza = stanza; | 490 stanza = stanza; |
491 is_first_session = is_first_dest_session; | 491 is_first_session = is_first_dest_session; |
492 is_last_session = is_last_orig_session; | 492 is_last_session = is_last_orig_session; |
493 }; | 493 }; |
494 local orig_nick = dest_occupant and dest_occupant.jid; | |
494 if orig_occupant == nil then | 495 if orig_occupant == nil then |
495 event_name = "muc-occupant-pre-join"; | 496 event_name = "muc-occupant-pre-join"; |
496 event.occupant = dest_occupant; | 497 event.occupant = dest_occupant; |
497 elseif dest_occupant == nil then | 498 elseif dest_occupant == nil then |
498 event_name = "muc-occupant-pre-leave"; | 499 event_name = "muc-occupant-pre-leave"; |
501 event_name = "muc-occupant-pre-change"; | 502 event_name = "muc-occupant-pre-change"; |
502 event.orig_occupant = orig_occupant; | 503 event.orig_occupant = orig_occupant; |
503 event.dest_occupant = dest_occupant; | 504 event.dest_occupant = dest_occupant; |
504 end | 505 end |
505 if module:fire_event(event_name, event) then return true; end | 506 if module:fire_event(event_name, event) then return true; end |
507 local nick_overridden = dest_occupant and orig_nick ~= dest_occupant.nick; | |
506 | 508 |
507 -- Check for nick conflicts | 509 -- Check for nick conflicts |
508 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 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 |
509 log("debug", "%s couldn't join due to nick conflict: %s", real_jid, dest_occupant.nick); | 511 log("debug", "%s couldn't join due to nick conflict: %s", real_jid, dest_occupant.nick); |
510 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); | 512 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); |
553 x:tag("status", {code = "110";}):up(); | 555 x:tag("status", {code = "110";}):up(); |
554 self:route_stanza(generated_unavail:add_child(x)); | 556 self:route_stanza(generated_unavail:add_child(x)); |
555 dest_nick = nil; -- set dest_nick to nil; so general populance doesn't see it for whole orig_occupant | 557 dest_nick = nil; -- set dest_nick to nil; so general populance doesn't see it for whole orig_occupant |
556 end | 558 end |
557 end | 559 end |
560 | |
558 self:save_occupant(orig_occupant); | 561 self:save_occupant(orig_occupant); |
559 self:publicise_occupant_status(orig_occupant, orig_x, dest_nick); | 562 self:publicise_occupant_status(orig_occupant, orig_x, dest_nick); |
560 | 563 |
561 if is_last_orig_session then | 564 if is_last_orig_session then |
562 module:fire_event("muc-occupant-left", { | 565 module:fire_event("muc-occupant-left", { |
572 if dest_occupant ~= nil then | 575 if dest_occupant ~= nil then |
573 dest_occupant:set_session(real_jid, stanza); | 576 dest_occupant:set_session(real_jid, stanza); |
574 local dest_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); | 577 local dest_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
575 if orig_occupant == nil and self:get_whois() == "anyone" then | 578 if orig_occupant == nil and self:get_whois() == "anyone" then |
576 dest_x:tag("status", {code = "100"}):up(); | 579 dest_x:tag("status", {code = "100"}):up(); |
580 end | |
581 if nick_overridden then | |
582 dest_x:tag("status", {code = "210"}):up(); | |
577 end | 583 end |
578 self:save_occupant(dest_occupant); | 584 self:save_occupant(dest_occupant); |
579 | 585 |
580 if orig_occupant == nil or muc_x then | 586 if orig_occupant == nil or muc_x then |
581 -- Send occupant list to newly joined user | 587 -- Send occupant list to newly joined user |