Comparison

plugins/muc/muc.lib.lua @ 6130:c95d9132592a

plugins/muc/muc.lib: Add route_to_occupant function to send a stanza to all occupant sessions
author daurnimator <quae@daurnimator.com>
date Thu, 20 Mar 2014 15:22:02 -0400
parent 6129:6c66571ab0f9
child 6131:8dd0c6145603
comparison
equal deleted inserted replaced
6129:6c66571ab0f9 6130:c95d9132592a
94 end 94 end
95 function room_mt:is_locked() 95 function room_mt:is_locked()
96 return not not self.locked 96 return not not self.locked
97 end 97 end
98 98
99 function room_mt:route_to_occupant(o_data, stanza)
100 local to = stanza.attr.to;
101 for jid in pairs(o_data.sessions) do
102 stanza.attr.to = jid;
103 self:_route_stanza(stanza);
104 end
105 stanza.attr.to = to;
106 end
107
99 function room_mt:broadcast_presence(stanza, sid, code, nick) 108 function room_mt:broadcast_presence(stanza, sid, code, nick)
100 stanza = get_filtered_presence(stanza); 109 stanza = get_filtered_presence(stanza);
101 local occupant = self._occupants[stanza.attr.from]; 110 local occupant = self._occupants[stanza.attr.from];
102 stanza:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) 111 stanza:tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
103 :tag("item", {affiliation=occupant.affiliation or "none", role=occupant.role or "none", nick=nick}):up(); 112 :tag("item", {affiliation=occupant.affiliation or "none", role=occupant.role or "none", nick=nick}):up();
111 stanza.attr.to = sid; 120 stanza.attr.to = sid;
112 self:_route_stanza(stanza); 121 self:_route_stanza(stanza);
113 end 122 end
114 end 123 end
115 function room_mt:broadcast_message(stanza, historic) 124 function room_mt:broadcast_message(stanza, historic)
116 local to = stanza.attr.to; 125 for occupant_jid, o_data in pairs(self._occupants) do
117 for occupant, o_data in pairs(self._occupants) do 126 self:route_to_occupant(o_data, stanza)
118 for jid in pairs(o_data.sessions) do 127 end
119 stanza.attr.to = jid;
120 self:_route_stanza(stanza);
121 end
122 end
123 stanza.attr.to = to;
124 if historic then -- add to history 128 if historic then -- add to history
125 return self:save_to_history(stanza) 129 return self:save_to_history(stanza)
126 end 130 end
127 end 131 end
128 function room_mt:save_to_history(stanza) 132 function room_mt:save_to_history(stanza)
658 return true; 662 return true;
659 end 663 end
660 log("debug", "%s sent private message stanza to %s (%s)", from, to, o_data.jid); 664 log("debug", "%s sent private message stanza to %s (%s)", from, to, o_data.jid);
661 stanza:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" }):up(); 665 stanza:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" }):up();
662 stanza.attr.from = current_nick; 666 stanza.attr.from = current_nick;
663 for jid in pairs(o_data.sessions) do 667 self:route_to_occupant(o_data, stanza)
664 stanza.attr.to = jid; 668 stanza.attr.from = from;
665 self:_route_stanza(stanza);
666 end
667 stanza.attr.from, stanza.attr.to = from, to;
668 return true; 669 return true;
669 end 670 end
670 671
671 function room_mt:send_form(origin, stanza) 672 function room_mt:send_form(origin, stanza)
672 origin.send(st.reply(stanza):query("http://jabber.org/protocol/muc#owner") 673 origin.send(st.reply(stanza):query("http://jabber.org/protocol/muc#owner")