Software /
code /
prosody-modules
Annotate
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 |
rev | line source |
---|---|
2081
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 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
|
3 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
|
4 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
|
5 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
|
6 local log = session.log or module._log; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 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
|
8 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
|
9 |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local room = jid_bare(stanza.attr.from); |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 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
|
12 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
|
13 joined = true; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 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
|
15 joined = nil; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 else |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 -- 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
|
18 return; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 end |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 -- 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 else |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 rooms[room] = joined; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 end |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 return; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 end |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 end); |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 -- TODO Check session.directed for outgoing presence? |