Comparison

mod_carbons/mod_carbons.lua @ 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
parent 618:267548522810
child 743:5f7dd5336dbe
comparison
equal deleted inserted replaced
663:a826b61c8f3a 664:2f11d2473afd
78 end); 78 end);
79 module:log("debug", "Message tagged private, ignoring"); 79 module:log("debug", "Message tagged private, ignoring");
80 return 80 return
81 end 81 end
82 82
83 local msg = st.clone(stanza);
84 msg.attr.xmlns = msg.attr.xmlns or "jabber:client";
85 local fwd = st.message{ from = bare_jid, type = orig_type, }
86 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons }):up()
87 :tag("forwarded", { xmlns = xmlns_forward })
88 :add_child(msg):reset();
89
83 user_sessions = user_sessions and user_sessions.sessions; 90 user_sessions = user_sessions and user_sessions.sessions;
84 for resource, session in pairs(user_sessions) do 91 for resource, session in pairs(user_sessions) do
85 local full_jid = bare_jid .. "/" .. resource; 92 local full_jid = bare_jid .. "/" .. resource;
86 module:log("debug", "%s wants carbons: %s", session.full_jid, tostring(session.want_carbons)); 93 if session.want_carbons and ((c2s and session ~= origin) or (not c2s and not no_carbon_to[resource])) then
87 if session.want_carbons then 94 fwd.attr.to = full_jid;
88 if c2s then 95 module:log("debug", "Sending carbon to %s", full_jid);
89 module:log("debug", "Session is origin: %s", tostring(session == origin)); 96 session.send(fwd);
90 else
91 module:log("debug", "Session is in ignore list: %s", tostring(no_carbon_to[resource]));
92 end
93 if (c2s and session ~= origin) or (not c2s and not no_carbon_to[resource]) then
94 local msg = st.clone(stanza);
95 msg.attr.xmlns = msg.attr.xmlns or "jabber:client";
96 local fwd = st.message{
97 from = bare_jid,
98 to = full_jid,
99 type = orig_type,
100 }
101 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons }):up()
102 :tag("forwarded", { xmlns = xmlns_forward })
103 :add_child(msg);
104 module:log("debug", "Sending carbon");
105 session.send(fwd);
106 end
107 end 97 end
108 end 98 end
109 end 99 end
110 100
111 local function c2s_message_handler(event) 101 local function c2s_message_handler(event)