Mercurial > prosody-modules
annotate mod_track_muc_joins/mod_track_muc_joins.lua @ 2300:dded110af017
mod_statistics/stats: Guard usage of module:get_option() so we only call it when Prosody is running
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 18 Sep 2016 18:53:09 +0100 |
parents | 43e647b8dd9f |
children | 12249570352f |
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; |
2264
463e43dc0c4d
mod_track_muc_joins: Keep the nickname around
Kim Alvefur <zash@zash.se>
parents:
2158
diff
changeset
|
2 local jid_split = require "util.jid".split; |
2085
8cb8004091f8
mod_track_muc_joins: Add missing imports (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
2081
diff
changeset
|
3 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
|
4 |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 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
|
6 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
|
7 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
|
8 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
|
9 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
|
10 |
2081
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 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
|
12 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
|
13 |
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
|
14 local from_jid = stanza.attr.from; |
2156
3fcac143fe0b
mod_track_muc_joins: Check directed presence
Kim Alvefur <zash@zash.se>
parents:
2085
diff
changeset
|
15 local room = jid_bare(from_jid); |
2274
43e647b8dd9f
mod_track_muc_joins: Fix saving the room nick (was using the room node)
Kim Alvefur <zash@zash.se>
parents:
2264
diff
changeset
|
16 local _,_,nick = jid_split(from_jid); |
2081
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 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
|
18 if joined == nil then |
2264
463e43dc0c4d
mod_track_muc_joins: Keep the nickname around
Kim Alvefur <zash@zash.se>
parents:
2158
diff
changeset
|
19 joined = nick; |
2081
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 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
|
21 joined = nil; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 else |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 -- 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
|
24 return; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 end |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
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
|
27 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
|
28 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
|
29 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
|
30 |
2081
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 -- 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 else |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 rooms[room] = joined; |
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 return; |
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 end |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 end); |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 |