comparison plugins/mod_carbons.lua @ 10563:e8db377a2983

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Tue, 24 Dec 2019 00:39:45 +0100
parents 658b759a1f7a
children a62b981db0e2
comparison
equal deleted inserted replaced
10562:670afc079f68 10563:e8db377a2983
72 elseif not c2s and bare_jid == orig_from and stanza:get_child("x", "http://jabber.org/protocol/muc#user") then 72 elseif not c2s and bare_jid == orig_from and stanza:get_child("x", "http://jabber.org/protocol/muc#user") then
73 module:log("debug", "MUC PM, ignoring"); 73 module:log("debug", "MUC PM, ignoring");
74 return 74 return
75 end 75 end
76 76
77 -- Create the carbon copy and wrap it as per the Stanza Forwarding XEP 77 local carbon;
78 local copy = st.clone(stanza);
79 if c2s and not orig_to then
80 stanza.attr.to = bare_from;
81 end
82 copy.attr.xmlns = "jabber:client";
83 local carbon = st.message{ from = bare_jid, type = orig_type, }
84 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons })
85 :tag("forwarded", { xmlns = xmlns_forward })
86 :add_child(copy):reset();
87
88 user_sessions = user_sessions and user_sessions.sessions; 78 user_sessions = user_sessions and user_sessions.sessions;
89 for _, session in pairs(user_sessions) do 79 for _, session in pairs(user_sessions) do
90 -- Carbons are sent to resources that have enabled it 80 -- Carbons are sent to resources that have enabled it
91 if session.want_carbons 81 if session.want_carbons
92 -- but not the resource that sent the message, or the one that it's directed to 82 -- but not the resource that sent the message, or the one that it's directed to
93 and session ~= target_session 83 and session ~= target_session
94 -- and isn't among the top resources that would receive the message per standard routing rules 84 -- and isn't among the top resources that would receive the message per standard routing rules
95 and (c2s or session.priority ~= top_priority) then 85 and (c2s or session.priority ~= top_priority) then
86 if not carbon then
87 -- Create the carbon copy and wrap it as per the Stanza Forwarding XEP
88 local copy = st.clone(stanza);
89 if c2s and not orig_to then
90 stanza.attr.to = bare_from;
91 end
92 copy.attr.xmlns = "jabber:client";
93 carbon = st.message{ from = bare_jid, type = orig_type, }
94 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons })
95 :tag("forwarded", { xmlns = xmlns_forward })
96 :add_child(copy):reset();
97
98 end
99
96 carbon.attr.to = session.full_jid; 100 carbon.attr.to = session.full_jid;
97 module:log("debug", "Sending carbon to %s", session.full_jid); 101 module:log("debug", "Sending carbon to %s", session.full_jid);
98 session.send(carbon); 102 session.send(carbon);
99 end 103 end
100 end 104 end