view mod_muc_ping/mod_muc_ping.lua @ 3656:3e0f4d727825

mod_vcard_muc: Add an alternative method of signaling avatar change When the avatar has been changed, a signal is sent that the room configuration has changed. Clients then do a disco#info query to find the SHA-1 of the new avatar. They can then fetch it as before, or not if they have it cached already. This is meant to be less disruptive than signaling via presence, which caused problems for some clients. If clients transition to the new method, the old one can eventually be removed. The namespace is made up while waiting for standardization. Otherwise it is very close to what's described in https://xmpp.org/extensions/inbox/muc-avatars.html
author Kim Alvefur <zash@zash.se>
date Sun, 25 Aug 2019 20:46:43 +0200
parents a0ca5d0a49ba
children
line wrap: on
line source

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();
	event.reply:tag("feature", {var = "http://jabber.org/protocol/muc#self-ping-optimization"}):up();
end);