view mod_auto_answer_disco_info/mod_auto_answer_disco_info.lua @ 3171:f35b2b76df6d

mod_smacks_noerror: Add ability to silence errors if mod_offline is disabled This will also silence "message not delivered" errors if mod_offline is disabled and all clients are offline. This assumes working MAM for all clients (lready assumed by the rest of this module).
author tmolitor <thilo@eightysoft.de>
date Tue, 03 Jul 2018 01:03:48 +0200
parents 1fe7da46e915
children 4cdd1ddae72c
line wrap: on
line source

module:depends("cache_c2s_caps");

local st = require "util.stanza";

local function iq_stanza_handler(event)
	local stanza, origin = event.stanza, event.origin;
	local type = stanza.attr.type;

	local query = stanza:get_child("query", "http://jabber.org/protocol/disco#info");
	if type ~= "get" or query == nil then
		return;
	end

	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/full", iq_stanza_handler, 1);