Comparison

mod_muc_ping/mod_muc_ping.lua @ 3349:35dc7c38e362

mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping Also see #1220
author Kim Alvefur <zash@zash.se>
date Sun, 07 Oct 2018 03:39:35 +0200
child 3647:a0ca5d0a49ba
comparison
equal deleted inserted replaced
3348:f753cf4f7224 3349:35dc7c38e362
1 local st = require "util.stanza";
2 local jid_bare = import("util.jid", "bare");
3
4 local mod_muc = module:depends"muc";
5 local rooms = rawget(mod_muc, "rooms");
6 if not rooms then
7 module:log("warn", "mod_%s is compatible with Prosody up to 0.10.x", module.name);
8 return;
9 end
10
11 module:hook("iq/full", function (event)
12 local origin, stanza = event.origin, event.stanza;
13 if stanza.attr.type ~= "get" or not stanza:get_child("ping", "urn:xmpp:ping") then
14 return;
15 end
16
17 local from = stanza.attr.from;
18 local room_nick = stanza.attr.to;
19 local room_jid = jid_bare(room_nick);
20
21 local room = rooms[room_jid];
22 if not room then return; end
23
24 if room._jid_nick[from] == room_nick then
25 origin.send(st.reply(stanza));
26 return true;
27 end
28 end);
29
30 module:hook("muc-disco#info", function(event)
31 event.reply:tag("feature", {var="urn:xmpp:ping"}):up();
32 end);