Mercurial > prosody-modules
annotate mod_track_muc_joins/mod_track_muc_joins.lua @ 2191:e47046abf568
mod_http_upload: Add more logging
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 31 May 2016 17:10:46 +0200 |
parents | de3fb9d2673c |
children | 463e43dc0c4d |
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 |
2081
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 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
|
11 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
|
12 |
2157
7d1a22ac2a21
mod_track_muc_joins: Only check directed presence when joining (would be gone when leaving)
Kim Alvefur <zash@zash.se>
parents:
2156
diff
changeset
|
13 local from_jid = stanza.attr.from; |
2156
3fcac143fe0b
mod_track_muc_joins: Check directed presence
Kim Alvefur <zash@zash.se>
parents:
2085
diff
changeset
|
14 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
|
15 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
|
16 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
|
17 joined = true; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 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
|
19 joined = nil; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 else |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 -- 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
|
22 return; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 end |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 |
2157
7d1a22ac2a21
mod_track_muc_joins: Only check directed presence when joining (would be gone when leaving)
Kim Alvefur <zash@zash.se>
parents:
2156
diff
changeset
|
25 if joined and not session.directed or not session.directed[from_jid] then |
7d1a22ac2a21
mod_track_muc_joins: Only check directed presence when joining (would be gone when leaving)
Kim Alvefur <zash@zash.se>
parents:
2156
diff
changeset
|
26 return; -- Never sent presence there, can't be a MUC join |
7d1a22ac2a21
mod_track_muc_joins: Only check directed presence when joining (would be gone when leaving)
Kim Alvefur <zash@zash.se>
parents:
2156
diff
changeset
|
27 end |
7d1a22ac2a21
mod_track_muc_joins: Only check directed presence when joining (would be gone when leaving)
Kim Alvefur <zash@zash.se>
parents:
2156
diff
changeset
|
28 |
2081
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 |
2158
de3fb9d2673c
mod_track_muc_joins: Skip creating room map if leaving a room and it does not exist
Kim Alvefur <zash@zash.se>
parents:
2157
diff
changeset
|
36 if not joined then return; end |
2081
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 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
|
38 else |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 rooms[room] = joined; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 end |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 return; |
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 end); |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 |