Changeset

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
parents 3348:f753cf4f7224
children 3350:cb26d04b391c
files mod_muc_ping/README.markdown mod_muc_ping/mod_muc_ping.lua
diffstat 2 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_muc_ping/README.markdown	Sun Oct 07 03:39:35 2018 +0200
@@ -0,0 +1,5 @@
+This module implements the [Server
+Optimization](https://xmpp.org/extensions/xep-0410.html#serveroptimization)
+part of [XEP-0410: MUC Self-Ping]
+
+It should work with Prosody up until 0.10.x.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_muc_ping/mod_muc_ping.lua	Sun Oct 07 03:39:35 2018 +0200
@@ -0,0 +1,32 @@
+local st = require "util.stanza";
+local jid_bare = import("util.jid", "bare");
+
+local mod_muc = module:depends"muc";
+local rooms = rawget(mod_muc, "rooms");
+if not rooms then
+	module:log("warn", "mod_%s is compatible with Prosody up to 0.10.x", module.name);
+	return;
+end
+
+module:hook("iq/full", function (event)
+	local origin, stanza = event.origin, event.stanza;
+	if stanza.attr.type ~= "get" or not stanza:get_child("ping", "urn:xmpp:ping") then
+		return;
+	end
+
+	local from = stanza.attr.from;
+	local room_nick = stanza.attr.to;
+	local room_jid = jid_bare(room_nick);
+
+	local room = rooms[room_jid];
+	if not room then return; end
+
+	if room._jid_nick[from] == room_nick then
+		origin.send(st.reply(stanza));
+		return true;
+	end
+end);
+
+module:hook("muc-disco#info", function(event)
+	event.reply:tag("feature", {var="urn:xmpp:ping"}):up();
+end);