annotate mod_muc_batched_probe/mod_muc_batched_probe.lua @ 4000:d56b3c0195a8

mod_muc_batched_probe: New module
author JC Brand <jc@opkode.com>
date Wed, 29 Apr 2020 13:00:22 +0200
parents
children 845d13ab0dc0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4000
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
1 -- This module allows you to probe the MUC presences for multiple occupants.
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
2 -- Copyright (C) 2020 JC Brand
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
3
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
4 local st = require "util.stanza";
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
5 local mod_muc = module:depends"muc";
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
6 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
7 function (jid)
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
8 local rooms = rawget(mod_muc, "rooms");
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
9 return rooms[jid];
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
10 end
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
11
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
12 module:log("debug", "Module loaded");
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
13
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
14
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
15 local function respondToBatchedProbe(event)
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
16 local stanza = event.stanza;
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
17 if stanza.attr.type ~= "get" then
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
18 return;
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
19 end
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
20 local query = stanza:get_child("query", "http://jabber.org/protocol/muc#user");
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
21 if not query then
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
22 return;
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
23 end;
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
24
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
25 local room = get_room_from_jid(stanza.attr.to);
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
26 for item in query.get_children() do
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
27 local probed_jid = item.attr.jid;
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
28 room:respond_to_probe(stanza.attr.from, probed_jid);
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
29 end
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
30 event.origin.send(st.reply(stanza));
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
31 return true;
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
32 end
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
33
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
34
d56b3c0195a8 mod_muc_batched_probe: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
35 module:hook("iq/bare", respondToBatchedProbe, 1);