annotate mod_track_muc_joins/mod_track_muc_joins.lua @ 4838:fd2e48d4ac94

mod_bookmarks2: Advertise XEP-0049 support In the case mod_private isn’t loaded, some clients (like poezio) won’t even attempt to use Private XML Storage unless this feature is advertised. This is on the domain JID and not on the account JID!
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 26 Dec 2021 14:51:35 +0100
parents 443d9dae3216
children
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;
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;
2335
eb456fd639d2 mod_track_muc_joins: Check if the map of directed presence exists earlier (fixes traceback due to precedence error) (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents: 2302
diff changeset
9 if not session.directed then return end -- hasn't sent presence yet
2081
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 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
11
2081
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 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
13 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
14
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
15 local from_jid = stanza.attr.from;
2156
3fcac143fe0b mod_track_muc_joins: Check directed presence
Kim Alvefur <zash@zash.se>
parents: 2085
diff changeset
16 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
17 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
18 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
19 if joined == nil then
2264
463e43dc0c4d mod_track_muc_joins: Keep the nickname around
Kim Alvefur <zash@zash.se>
parents: 2158
diff changeset
20 joined = nick;
2081
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 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
22 joined = nil;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 else
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 -- 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
25 return;
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27
2335
eb456fd639d2 mod_track_muc_joins: Check if the map of directed presence exists earlier (fixes traceback due to precedence error) (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents: 2302
diff changeset
28 if joined and not session.directed[from_jid] then
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
29 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
30 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
31
2302
12249570352f mod_track_muc_joins: Use correct number in comment
Kim Alvefur <zash@zash.se>
parents: 2274
diff changeset
32 -- Check for status code 110, meaning it's their own reflected presence
2081
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 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
34 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
35 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
36 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
37 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
38 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
39 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
40 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
41 else
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 rooms[room] = joined;
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 return;
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
2339
443d9dae3216 mod_track_muc_joins: Bump priority up over mod_presence to ensure event is caught
Kim Alvefur <zash@zash.se>
parents: 2335
diff changeset
47 end, 1);
2081
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48