comparison mod_track_muc_joins/mod_track_muc_joins.lua @ 2160:394a62163a91

Merge
author JC Brand <jc@opkode.com>
date Fri, 15 Apr 2016 13:59:45 +0000
parents de3fb9d2673c
children 463e43dc0c4d
comparison
equal deleted inserted replaced
2159:5e8dec076afc 2160:394a62163a91
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
9 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); 10 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc#user");
10 if not muc_x then return end -- Not MUC related 11 if not muc_x then return end -- Not MUC related
11 12
12 local room = jid_bare(stanza.attr.from); 13 local from_jid = stanza.attr.from;
14 local room = jid_bare(from_jid);
13 local joined = stanza.attr.type; 15 local joined = stanza.attr.type;
14 if joined == nil then 16 if joined == nil then
15 joined = true; 17 joined = true;
16 elseif joined == "unavailable" then 18 elseif joined == "unavailable" then
17 joined = nil; 19 joined = nil;
18 else 20 else
19 -- Ignore errors and whatever 21 -- Ignore errors and whatever
20 return; 22 return;
21 end 23 end
22 24
25 if joined and not session.directed or not session.directed[from_jid] then
26 return; -- Never sent presence there, can't be a MUC join
27 end
28
23 -- Check for status code 100, meaning it's their own reflected presence 29 -- Check for status code 100, meaning it's their own reflected presence
24 for status in muc_x:childtags("status") do 30 for status in muc_x:childtags("status") do
25 log("debug", "Status code %d", status.attr.code); 31 log("debug", "Status code %d", status.attr.code);
26 if status.attr.code == "110" then 32 if status.attr.code == "110" then
27 log("debug", "%s room %s", joined and "Joined" or "Left", room); 33 log("debug", "%s room %s", joined and "Joined" or "Left", room);
28 local rooms = session.rooms_joined; 34 local rooms = session.rooms_joined;
29 if not rooms then 35 if not rooms then
36 if not joined then return; end
30 session.rooms_joined = { [room] = joined }; 37 session.rooms_joined = { [room] = joined };
31 else 38 else
32 rooms[room] = joined; 39 rooms[room] = joined;
33 end 40 end
34 return; 41 return;
35 end 42 end
36 end 43 end
37 end); 44 end);
38 45
39 -- TODO Check session.directed for outgoing presence?