Comparison

plugins/muc/muc.lib.lua @ 8481:d546815e555e

MUC: Move delayed delivery check into an event handler
author Kim Alvefur <zash@zash.se>
date Thu, 21 Dec 2017 13:38:59 +0100
parent 8480:3d3706147174
child 8482:8b2219011386
comparison
equal deleted inserted replaced
8480:3d3706147174 8481:d546815e555e
162 end 162 end
163 return x 163 return x
164 end 164 end
165 165
166 function room_mt:broadcast_message(stanza) 166 function room_mt:broadcast_message(stanza)
167 if module:fire_event("muc-broadcast-message", {room = self, stanza = stanza}) then
168 return true;
169 end
170 self:broadcast(stanza);
171 return true;
172 end
173
174 -- Strip delay tags claiming to be from us
175 module:hook("muc-broadcast-message", function (event)
176 local stanza = event.stanza;
167 local to = stanza.attr.to; 177 local to = stanza.attr.to;
168 local room_jid = self.jid; 178 local room_jid = self.jid;
169 179
170 stanza:maptags(function (child) 180 stanza:maptags(function (child)
171 if child.name == "delay" and child.attr["xmlns"] == "urn:xmpp:delay" then 181 if child.name == "delay" and child.attr["xmlns"] == "urn:xmpp:delay" then
178 return nil; 188 return nil;
179 end 189 end
180 end 190 end
181 return child; 191 return child;
182 end) 192 end)
183 193 end);
184 if module:fire_event("muc-broadcast-message", {room = self, stanza = stanza}) then
185 return true;
186 end
187 self:broadcast(stanza);
188 return true;
189 end
190 194
191 -- Broadcast a stanza to all occupants in the room. 195 -- Broadcast a stanza to all occupants in the room.
192 -- optionally checks conditional called with (nick, occupant) 196 -- optionally checks conditional called with (nick, occupant)
193 function room_mt:broadcast(stanza, cond_func) 197 function room_mt:broadcast(stanza, cond_func)
194 for nick, occupant in self:each_occupant() do 198 for nick, occupant in self:each_occupant() do