comparison mod_track_muc_joins/mod_track_muc_joins.lua @ 2156:3fcac143fe0b

mod_track_muc_joins: Check directed presence
author Kim Alvefur <zash@zash.se>
date Tue, 12 Apr 2016 16:05:21 +0200
parents 8cb8004091f8
children 7d1a22ac2a21
comparison
equal deleted inserted replaced
2155:f24b02e0d706 2156:3fcac143fe0b
4 module:hook("presence/full", function (event) 4 module:hook("presence/full", function (event)
5 local stanza = event.stanza; 5 local stanza = event.stanza;
6 local session = sessions[stanza.attr.to]; 6 local session = sessions[stanza.attr.to];
7 if not session then return end; 7 if not session then return end;
8 local log = session.log or module._log; 8 local log = session.log or module._log;
9
10 local from_jid = stanza.attr.from;
11 if not session.directed or not session.directed[from_jid] then
12 return; -- Never sent presence there, can't be a MUC join
13 end
14
9 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); 15 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc#user");
10 if not muc_x then return end -- Not MUC related 16 if not muc_x then return end -- Not MUC related
11 17
12 local room = jid_bare(stanza.attr.from); 18 local room = jid_bare(from_jid);
13 local joined = stanza.attr.type; 19 local joined = stanza.attr.type;
14 if joined == nil then 20 if joined == nil then
15 joined = true; 21 joined = true;
16 elseif joined == "unavailable" then 22 elseif joined == "unavailable" then
17 joined = nil; 23 joined = nil;
34 return; 40 return;
35 end 41 end
36 end 42 end
37 end); 43 end);
38 44
39 -- TODO Check session.directed for outgoing presence?