annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2085
8cb8004091f8 mod_track_muc_joins: Add missing imports (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
1 local jid_bare = require "util.jid".bare;
8cb8004091f8 mod_track_muc_joins: Add missing imports (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
2 local sessions = prosody.full_sessions;
2081
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 module:hook("presence/full", function (event)
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local stanza = event.stanza;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local session = sessions[stanza.attr.to];
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 if not session then return end;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local log = session.log or module._log;
2156
3fcac143fe0b mod_track_muc_joins: Check directed presence
Kim Alvefur <zash@zash.se>
parents: 2085
diff changeset
9
3fcac143fe0b mod_track_muc_joins: Check directed presence
Kim Alvefur <zash@zash.se>
parents: 2085
diff changeset
10 local from_jid = stanza.attr.from;
3fcac143fe0b mod_track_muc_joins: Check directed presence
Kim Alvefur <zash@zash.se>
parents: 2085
diff changeset
11 if not session.directed or not session.directed[from_jid] then
3fcac143fe0b mod_track_muc_joins: Check directed presence
Kim Alvefur <zash@zash.se>
parents: 2085
diff changeset
12 return; -- Never sent presence there, can't be a MUC join
3fcac143fe0b mod_track_muc_joins: Check directed presence
Kim Alvefur <zash@zash.se>
parents: 2085
diff changeset
13 end
3fcac143fe0b mod_track_muc_joins: Check directed presence
Kim Alvefur <zash@zash.se>
parents: 2085
diff changeset
14
2081
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc#user");
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 if not muc_x then return end -- Not MUC related
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17
2156
3fcac143fe0b mod_track_muc_joins: Check directed presence
Kim Alvefur <zash@zash.se>
parents: 2085
diff changeset
18 local room = jid_bare(from_jid);
2081
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local joined = stanza.attr.type;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 if joined == nil then
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 joined = true;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 elseif joined == "unavailable" then
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 joined = nil;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 else
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 -- Ignore errors and whatever
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 return;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 -- Check for status code 100, meaning it's their own reflected presence
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 for status in muc_x:childtags("status") do
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 log("debug", "Status code %d", status.attr.code);
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 if status.attr.code == "110" then
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 log("debug", "%s room %s", joined and "Joined" or "Left", room);
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 local rooms = session.rooms_joined;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 if not rooms then
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 session.rooms_joined = { [room] = joined };
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 else
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 rooms[room] = joined;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 end
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 return;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 end
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 end);
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44