Changeset

664:2f11d2473afd

mod_carbons: Move creation of the carbon stanza out of the loop.
author Kim Alvefur <zash@zash.se>
date Sun, 06 May 2012 23:27:28 +0200
parents 663:a826b61c8f3a
children 665:684cc57a49c1
files mod_carbons/mod_carbons.lua
diffstat 1 files changed, 11 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/mod_carbons/mod_carbons.lua	Mon Apr 30 17:25:09 2012 +0200
+++ b/mod_carbons/mod_carbons.lua	Sun May 06 23:27:28 2012 +0200
@@ -80,30 +80,20 @@
 		return
 	end
 
+	local msg = st.clone(stanza);
+	msg.attr.xmlns = msg.attr.xmlns or "jabber:client";
+	local fwd = st.message{ from = bare_jid, type = orig_type, }
+		:tag(c2s and "sent" or "received", { xmlns = xmlns_carbons }):up()
+			:tag("forwarded", { xmlns = xmlns_forward })
+				:add_child(msg):reset();
+
 	user_sessions = user_sessions and user_sessions.sessions;
 	for resource, session in pairs(user_sessions) do
 		local full_jid = bare_jid .. "/" .. resource;
-		module:log("debug", "%s wants carbons: %s", session.full_jid, tostring(session.want_carbons));
-		if session.want_carbons then
-			if c2s then
-				module:log("debug", "Session is origin: %s", tostring(session == origin));
-			else
-				module:log("debug", "Session is in ignore list: %s", tostring(no_carbon_to[resource]));
-			end
-			if (c2s and session ~= origin) or (not c2s and not no_carbon_to[resource]) then
-				local msg = st.clone(stanza);
-				msg.attr.xmlns = msg.attr.xmlns or "jabber:client";
-				local fwd = st.message{
-					from = bare_jid,
-					to = full_jid,
-					type = orig_type,
-				}
-				:tag(c2s and "sent" or "received", { xmlns = xmlns_carbons }):up()
-				:tag("forwarded", { xmlns = xmlns_forward })
-				:add_child(msg);
-				module:log("debug", "Sending carbon");
-				session.send(fwd);
-			end
+		if session.want_carbons and ((c2s and session ~= origin) or (not c2s and not no_carbon_to[resource])) then
+			fwd.attr.to = full_jid;
+			module:log("debug", "Sending carbon to %s", full_jid);
+			session.send(fwd);
 		end
 	end
 end