aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc/muc.lib.lua
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2014-03-24 16:32:18 -0400
committerdaurnimator <quae@daurnimator.com>2014-03-24 16:32:18 -0400
commit2e431e6c6dbb1b184775d4b47780317688a09443 (patch)
treeec56661434f3f7107114bb939b1f957c81a16b62 /plugins/muc/muc.lib.lua
parent9b13e219b6b39ba568f62cf821b9a68bc4c56930 (diff)
downloadprosody-2e431e6c6dbb1b184775d4b47780317688a09443.tar.gz
prosody-2e431e6c6dbb1b184775d4b47780317688a09443.zip
plugins/muc/muc.lib: Add :broadcast method; use it from :broadcast_except_nick and :broadcast_message
Diffstat (limited to 'plugins/muc/muc.lib.lua')
-rw-r--r--plugins/muc/muc.lib.lua14
1 files changed, 9 insertions, 5 deletions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index d0a5641c..c955d47b 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -120,9 +120,7 @@ function room_mt:broadcast_presence(stanza, sid, code, nick)
end
function room_mt:broadcast_message(stanza, historic)
module:fire_event("muc-broadcast-message", {room = self, stanza = stanza, historic = historic});
- for occupant_jid, o_data in pairs(self._occupants) do
- self:route_to_occupant(o_data, stanza)
- end
+ self:broadcast(stanza);
end
-- add to history
@@ -143,8 +141,14 @@ module:hook("muc-broadcast-message", function(event)
end)
function room_mt:broadcast_except_nick(stanza, nick)
- for rnick, occupant in pairs(self._occupants) do
- if rnick ~= nick then
+ return self:broadcast(stanza, function(rnick, occupant) return rnick ~= nick end)
+end
+
+-- Broadcast a stanza to all occupants in the room.
+-- optionally checks conditional called with nicl
+function room_mt:broadcast(stanza, cond_func)
+ for nick, occupant in pairs(self._occupants) do
+ if cond_func == nil or cond_func(nick, occupant) then
self:route_to_occupant(occupant, stanza)
end
end