Changeset

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
parents 6129:6c66571ab0f9
children 6131:8dd0c6145603
files plugins/muc/muc.lib.lua
diffstat 1 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Thu Mar 20 11:06:10 2014 -0400
+++ b/plugins/muc/muc.lib.lua	Thu Mar 20 15:22:02 2014 -0400
@@ -96,6 +96,15 @@
 	return not not self.locked
 end
 
+function room_mt:route_to_occupant(o_data, stanza)
+	local to = stanza.attr.to;
+	for jid in pairs(o_data.sessions) do
+		stanza.attr.to = jid;
+		self:_route_stanza(stanza);
+	end
+	stanza.attr.to = to;
+end
+
 function room_mt:broadcast_presence(stanza, sid, code, nick)
 	stanza = get_filtered_presence(stanza);
 	local occupant = self._occupants[stanza.attr.from];
@@ -113,14 +122,9 @@
 	end
 end
 function room_mt:broadcast_message(stanza, historic)
-	local to = stanza.attr.to;
-	for occupant, o_data in pairs(self._occupants) do
-		for jid in pairs(o_data.sessions) do
-			stanza.attr.to = jid;
-			self:_route_stanza(stanza);
-		end
+	for occupant_jid, o_data in pairs(self._occupants) do
+		self:route_to_occupant(o_data, stanza)
 	end
-	stanza.attr.to = to;
 	if historic then -- add to history
 		return self:save_to_history(stanza)
 	end
@@ -660,11 +664,8 @@
 	log("debug", "%s sent private message stanza to %s (%s)", from, to, o_data.jid);
 	stanza:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" }):up();
 	stanza.attr.from = current_nick;
-	for jid in pairs(o_data.sessions) do
-		stanza.attr.to = jid;
-		self:_route_stanza(stanza);
-	end
-	stanza.attr.from, stanza.attr.to = from, to;
+	self:route_to_occupant(o_data, stanza)
+	stanza.attr.from = from;
 	return true;
 end