Software /
code /
prosody-modules
Annotate
mod_track_muc_joins/mod_track_muc_joins.lua @ 2111:4e434abaf8fc
mod_firewall: README: Improve chain documentation
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 17 Mar 2016 11:51:05 +0000 |
parent | 2085:8cb8004091f8 |
child | 2156:3fcac143fe0b |
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; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 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
|
10 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
|
11 |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 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
|
13 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
|
14 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
|
15 joined = true; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 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
|
17 joined = nil; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 else |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 -- 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
|
20 return; |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 end |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 -- 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 else |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 rooms[room] = joined; |
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 return; |
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 end |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 end); |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 |
73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 -- TODO Check session.directed for outgoing presence? |