Software /
code /
prosody-modules
Comparison
mod_track_muc_joins/mod_track_muc_joins.lua @ 2081:73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 14 Mar 2016 13:36:12 +0100 |
child | 2085:8cb8004091f8 |
comparison
equal
deleted
inserted
replaced
2080:a435db77a5e5 | 2081:73096d8d924c |
---|---|
1 | |
2 module:hook("presence/full", function (event) | |
3 local stanza = event.stanza; | |
4 local session = sessions[stanza.attr.to]; | |
5 if not session then return end; | |
6 local log = session.log or module._log; | |
7 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); | |
8 if not muc_x then return end -- Not MUC related | |
9 | |
10 local room = jid_bare(stanza.attr.from); | |
11 local joined = stanza.attr.type; | |
12 if joined == nil then | |
13 joined = true; | |
14 elseif joined == "unavailable" then | |
15 joined = nil; | |
16 else | |
17 -- Ignore errors and whatever | |
18 return; | |
19 end | |
20 | |
21 -- Check for status code 100, meaning it's their own reflected presence | |
22 for status in muc_x:childtags("status") do | |
23 log("debug", "Status code %d", status.attr.code); | |
24 if status.attr.code == "110" then | |
25 log("debug", "%s room %s", joined and "Joined" or "Left", room); | |
26 local rooms = session.rooms_joined; | |
27 if not rooms then | |
28 session.rooms_joined = { [room] = joined }; | |
29 else | |
30 rooms[room] = joined; | |
31 end | |
32 return; | |
33 end | |
34 end | |
35 end); | |
36 | |
37 -- TODO Check session.directed for outgoing presence? |