annotate mod_muc_ping/mod_muc_ping.lua @ 4688:05725276fac0

mod_bookmarks2: Use same default as mod_pep for max_items Should fix the issue with max items until the proper "max" can be used, by following the configured max. While "max" is already in trunk, it's not easily usable in 0.11.x This limit and option was added to mod_pep in Prosody rev aefb96a52f5f
author Kim Alvefur <zash@zash.se>
date Wed, 15 Sep 2021 17:39:37 +0200
parents a0ca5d0a49ba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3349
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local st = require "util.stanza";
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local jid_bare = import("util.jid", "bare");
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local mod_muc = module:depends"muc";
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local rooms = rawget(mod_muc, "rooms");
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 if not rooms then
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 module:log("warn", "mod_%s is compatible with Prosody up to 0.10.x", module.name);
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 return;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 end
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 module:hook("iq/full", function (event)
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local origin, stanza = event.origin, event.stanza;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 if stanza.attr.type ~= "get" or not stanza:get_child("ping", "urn:xmpp:ping") then
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 return;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 end
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local from = stanza.attr.from;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 local room_nick = stanza.attr.to;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local room_jid = jid_bare(room_nick);
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 local room = rooms[room_jid];
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 if not room then return; end
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 if room._jid_nick[from] == room_nick then
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 origin.send(st.reply(stanza));
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 return true;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end);
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 module:hook("muc-disco#info", function(event)
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 event.reply:tag("feature", {var="urn:xmpp:ping"}):up();
3647
a0ca5d0a49ba mod_muc_ping: Advertise XEP-0410 feature
Kim Alvefur <zash@zash.se>
parents: 3349
diff changeset
32 event.reply:tag("feature", {var = "http://jabber.org/protocol/muc#self-ping-optimization"}):up();
3349
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 end);