Diff

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
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Mon Mar 24 13:36:43 2014 -0400
+++ b/plugins/muc/muc.lib.lua	Mon Mar 24 16:32:18 2014 -0400
@@ -120,9 +120,7 @@
 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 @@
 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