view mod_auto_answer_disco_info/mod_auto_answer_disco_info.lua @ 4530:33c149d0261d

mod_rest: Add mappings for a whole pile of XEPs Look ma, programming in JSON! XEP-0012: Last Activity XEP-0077: In-Band Registration XEP-0115: Entity Capabilities XEP-0153: vCard-Based Avatars XEP-0297: Stanza Forwarding XEP-0308: Last Message Correction XEP-0319: Last User Interaction in Presence XEP-0333: Chat Markers XEP-0367: Message Attaching XEP-0372: References XEP-0421: Anonymous unique occupant identifiers for MUCs XEP-0428: Fallback Indication XEP-0444: Message Reactions
author Kim Alvefur <zash@zash.se>
date Tue, 23 Mar 2021 23:18:33 +0100
parents 4cdd1ddae72c
children 05c74210c007
line wrap: on
line source

module:depends("cache_c2s_caps");

local st = require "util.stanza";

local function disco_handler(event)
	local stanza, origin = event.stanza, event.origin;
	local query = stanza.tags[1];
	local to = stanza.attr.to;
	local node = query.attr.node;

	local target_session = prosody.full_sessions[to];
	if target_session == nil then
		return;
	end

	local disco_info = target_session.caps_cache;
	if disco_info ~= nil and (node == nil or node == disco_info.attr.node) then
		local iq = st.reply(stanza);
		iq:add_child(st.clone(disco_info));
		local log = origin.log or module._log;
		log("debug", "Answering disco#info on the behalf of %s", to);
		module:send(iq);
		return true;
	end
end

module:hook("iq-get/full/http://jabber.org/protocol/disco#info:query", disco_handler, 1);