Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 9081:ce57c69a20e2
MUC: Split long lines [luacheck strict]
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 03 Aug 2018 17:48:41 +0200 |
parent | 9057:df18f8398548 |
child | 9145:51c5dd7a8ab9 |
comparison
equal
deleted
inserted
replaced
9080:1b21f8ffaec8 | 9081:ce57c69a20e2 |
---|---|
490 local orig_occupant = self:get_occupant_by_real_jid(real_jid); | 490 local orig_occupant = self:get_occupant_by_real_jid(real_jid); |
491 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc"); | 491 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc"); |
492 | 492 |
493 if orig_occupant == nil and not muc_x and stanza.attr.type == nil then | 493 if orig_occupant == nil and not muc_x and stanza.attr.type == nil then |
494 module:log("debug", "Attempted join without <x>, possibly desynced"); | 494 module:log("debug", "Attempted join without <x>, possibly desynced"); |
495 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "You must join the room before sending presence updates")); | 495 origin.send(st.error_reply(stanza, "cancel", "item-not-found", |
496 "You must join the room before sending presence updates")); | |
496 return true; | 497 return true; |
497 end | 498 end |
498 | 499 |
499 local is_first_dest_session; | 500 local is_first_dest_session; |
500 local dest_occupant; | 501 local dest_occupant; |
589 -- don't want to get our old nick's available presence, | 590 -- don't want to get our old nick's available presence, |
590 -- so remove our session from there, and manually generate an unavailable | 591 -- so remove our session from there, and manually generate an unavailable |
591 orig_occupant:remove_session(real_jid); | 592 orig_occupant:remove_session(real_jid); |
592 log("debug", "generating nick change for %s", real_jid); | 593 log("debug", "generating nick change for %s", real_jid); |
593 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); | 594 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
594 -- self:build_item_list(orig_occupant, x, false, dest_nick); -- COMPAT: clients get confused if they see other items besides their own | 595 -- COMPAT: clients get confused if they see other items besides their own |
596 -- self:build_item_list(orig_occupant, x, false, dest_nick); | |
595 add_item(x, self:get_affiliation(bare_jid), orig_occupant.role, real_jid, dest_nick); | 597 add_item(x, self:get_affiliation(bare_jid), orig_occupant.role, real_jid, dest_nick); |
596 x:tag("status", {code = "303";}):up(); | 598 x:tag("status", {code = "303";}):up(); |
597 x:tag("status", {code = "110";}):up(); | 599 x:tag("status", {code = "110";}):up(); |
598 self:route_stanza(generated_unavail:add_child(x)); | 600 self:route_stanza(generated_unavail:add_child(x)); |
599 dest_nick = nil; -- set dest_nick to nil; so general populance doesn't see it for whole orig_occupant | 601 dest_nick = nil; -- set dest_nick to nil; so general populance doesn't see it for whole orig_occupant |
633 if nick_changed then | 635 if nick_changed then |
634 self_x:tag("status", {code="210"}):up(); | 636 self_x:tag("status", {code="210"}):up(); |
635 end | 637 end |
636 self:publicise_occupant_status(dest_occupant, {base=dest_x,self=self_x}); | 638 self:publicise_occupant_status(dest_occupant, {base=dest_x,self=self_x}); |
637 | 639 |
638 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 | 640 if orig_occupant ~= nil and orig_occupant ~= dest_occupant and not is_last_orig_session then |
641 -- If user is swapping and wasn't last original session | |
639 log("debug", "session %s split nicks; showing %s rejoining", real_jid, orig_occupant.nick); | 642 log("debug", "session %s split nicks; showing %s rejoining", real_jid, orig_occupant.nick); |
640 -- Show the original nick joining again | 643 -- Show the original nick joining again |
641 local pr = st.clone(orig_occupant:get_presence()); | 644 local pr = st.clone(orig_occupant:get_presence()); |
642 pr.attr.to = real_jid; | 645 pr.attr.to = real_jid; |
643 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); | 646 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
890 if not item.attr.jid then | 893 if not item.attr.jid then |
891 origin.send(st.error_reply(stanza, "modify", "jid-malformed")); | 894 origin.send(st.error_reply(stanza, "modify", "jid-malformed")); |
892 return true; | 895 return true; |
893 end | 896 end |
894 end | 897 end |
895 if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation | 898 if not item.attr.jid and item.attr.nick then |
899 -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation | |
896 local occupant = self:get_occupant_by_nick(self.jid.."/"..item.attr.nick); | 900 local occupant = self:get_occupant_by_nick(self.jid.."/"..item.attr.nick); |
897 if occupant then item.attr.jid = occupant.jid; end | 901 if occupant then item.attr.jid = occupant.jid; end |
898 elseif not item.attr.nick and item.attr.jid then | 902 elseif not item.attr.nick and item.attr.jid then |
899 local nick = self:get_occupant_jid(item.attr.jid); | 903 local nick = self:get_occupant_jid(item.attr.jid); |
900 if nick then item.attr.nick = jid_resource(nick); end | 904 if nick then item.attr.nick = jid_resource(nick); end |
1129 module:hook("muc-decline", function(event) | 1133 module:hook("muc-decline", function(event) |
1130 local room, stanza = event.room, event.stanza; | 1134 local room, stanza = event.room, event.stanza; |
1131 if not stanza:get_child("body") then | 1135 if not stanza:get_child("body") then |
1132 local decline = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("decline"); | 1136 local decline = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("decline"); |
1133 local reason = decline:get_child_text("reason") or ""; | 1137 local reason = decline:get_child_text("reason") or ""; |
1134 stanza:tag("body") | 1138 stanza:body(decline.attr.from.." declined your invite to the room " |
1135 :text(decline.attr.from.." declined your invite to the room "..room.jid..(reason ~= "" and (" ("..reason..")") or "")) | 1139 ..room.jid..(reason ~= "" and (" ("..reason..")") or "")); |
1136 :up(); | |
1137 end | 1140 end |
1138 end); | 1141 end); |
1139 | 1142 |
1140 function room_mt:handle_message_to_room(origin, stanza) | 1143 function room_mt:handle_message_to_room(origin, stanza) |
1141 local type = stanza.attr.type; | 1144 local type = stanza.attr.type; |
1171 module:send(stanza); | 1174 module:send(stanza); |
1172 end | 1175 end |
1173 | 1176 |
1174 function room_mt:get_affiliation(jid) | 1177 function room_mt:get_affiliation(jid) |
1175 local node, host, resource = jid_split(jid); | 1178 local node, host, resource = jid_split(jid); |
1179 -- Affiliations are granted, revoked, and maintained based on the user's bare JID. | |
1176 local bare = node and node.."@"..host or host; | 1180 local bare = node and node.."@"..host or host; |
1177 local result = self._affiliations[bare]; -- Affiliations are granted, revoked, and maintained based on the user's bare JID. | 1181 local result = self._affiliations[bare]; |
1178 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned | 1182 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned |
1179 return result; | 1183 return result; |
1180 end | 1184 end |
1181 | 1185 |
1182 -- Iterates over jid, affiliation pairs | 1186 -- Iterates over jid, affiliation pairs |