view mod_discoitems/mod_discoitems.lua @ 6519:01d8bfbfc435

mod_pubsub_serverinfo: Fix check for local domain The module was checking whether a host exists, but this may be misleading if our host is loaded before the host that is being checked. This change makes it check the config. This will provide a false positive in the rare case that the host is defined but not activated/enabled. But we don't have an API currently for "is this host configured and enabled?"
author Matthew Wild <mwild1@gmail.com>
date Tue, 21 Apr 2026 19:54:19 +0100
parents ae91c98b7e4c
children
line wrap: on
line source

-- mod_discoitems.lua
--
-- In the config, you can add:
--
-- disco_items = {
--  {"proxy.eu.jabber.org", "Jabber.org SOCKS5 service"};
--  {"conference.jabber.org", "The Jabber.org MUC"};
-- };
--

local st = require "util.stanza";

local result_query = st.stanza("query", {xmlns="http://jabber.org/protocol/disco#items"});
for _, item in ipairs(module:get_option("disco_items") or {}) do
	result_query:tag("item", {jid=item[1], name=item[2]}):up();
end

module:hook('iq/host/http://jabber.org/protocol/disco#items:query', function(event)
	local stanza = event.stanza;
	local query = stanza.tags[1];
	if stanza.attr.type == 'get' and not query.attr.node then
		event.origin.send(st.reply(stanza):add_child(result_query));
		return true;
	end
end, 100);