Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 6140:e4cdb3e5d7d0
plugins/muc/muc.lib: Add :broadcast method; use it from :broadcast_except_nick and :broadcast_message
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Mon, 24 Mar 2014 16:32:18 -0400 |
parent | 6139:544f75256883 |
child | 6141:bf6de8ef66c2 |
comparison
equal
deleted
inserted
replaced
6139:544f75256883 | 6140:e4cdb3e5d7d0 |
---|---|
118 stanza.attr.to = sid; | 118 stanza.attr.to = sid; |
119 self:_route_stanza(stanza); | 119 self:_route_stanza(stanza); |
120 end | 120 end |
121 function room_mt:broadcast_message(stanza, historic) | 121 function room_mt:broadcast_message(stanza, historic) |
122 module:fire_event("muc-broadcast-message", {room = self, stanza = stanza, historic = historic}); | 122 module:fire_event("muc-broadcast-message", {room = self, stanza = stanza, historic = historic}); |
123 for occupant_jid, o_data in pairs(self._occupants) do | 123 self:broadcast(stanza); |
124 self:route_to_occupant(o_data, stanza) | |
125 end | |
126 end | 124 end |
127 | 125 |
128 -- add to history | 126 -- add to history |
129 module:hook("muc-broadcast-message", function(event) | 127 module:hook("muc-broadcast-message", function(event) |
130 if event.historic then | 128 if event.historic then |
141 while #history > room:get_historylength() do t_remove(history, 1) end | 139 while #history > room:get_historylength() do t_remove(history, 1) end |
142 end | 140 end |
143 end) | 141 end) |
144 | 142 |
145 function room_mt:broadcast_except_nick(stanza, nick) | 143 function room_mt:broadcast_except_nick(stanza, nick) |
146 for rnick, occupant in pairs(self._occupants) do | 144 return self:broadcast(stanza, function(rnick, occupant) return rnick ~= nick end) |
147 if rnick ~= nick then | 145 end |
146 | |
147 -- Broadcast a stanza to all occupants in the room. | |
148 -- optionally checks conditional called with nicl | |
149 function room_mt:broadcast(stanza, cond_func) | |
150 for nick, occupant in pairs(self._occupants) do | |
151 if cond_func == nil or cond_func(nick, occupant) then | |
148 self:route_to_occupant(occupant, stanza) | 152 self:route_to_occupant(occupant, stanza) |
149 end | 153 end |
150 end | 154 end |
151 end | 155 end |
152 | 156 |