4000
|
1 -- This module allows you to probe the MUC presences for multiple occupants.
|
|
2 -- Copyright (C) 2020 JC Brand
|
|
3
|
|
4 local st = require "util.stanza";
|
|
5 local mod_muc = module:depends"muc";
|
|
6 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or
|
|
7 function (jid)
|
|
8 local rooms = rawget(mod_muc, "rooms");
|
|
9 return rooms[jid];
|
|
10 end
|
|
11
|
|
12 module:log("debug", "Module loaded");
|
|
13
|
|
14
|
|
15 local function respondToBatchedProbe(event)
|
|
16 local stanza = event.stanza;
|
|
17 if stanza.attr.type ~= "get" then
|
|
18 return;
|
|
19 end
|
|
20 local query = stanza:get_child("query", "http://jabber.org/protocol/muc#user");
|
|
21 if not query then
|
|
22 return;
|
|
23 end;
|
|
24
|
|
25 local room = get_room_from_jid(stanza.attr.to);
|
|
26 for item in query.get_children() do
|
|
27 local probed_jid = item.attr.jid;
|
|
28 room:respond_to_probe(stanza.attr.from, probed_jid);
|
|
29 end
|
|
30 event.origin.send(st.reply(stanza));
|
|
31 return true;
|
|
32 end
|
|
33
|
|
34
|
|
35 module:hook("iq/bare", respondToBatchedProbe, 1);
|