From 8408229cbeb8f92dae2e9ff12a265fd4837cd7e2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 6 Jul 2018 18:00:50 +0200 Subject: mod_pubsub: Move service discovery to pubsub.lib to allow reuse --- plugins/mod_pubsub/pubsub.lib.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'plugins/mod_pubsub/pubsub.lib.lua') diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua index 0aedda1a..83fba1fc 100644 --- a/plugins/mod_pubsub/pubsub.lib.lua +++ b/plugins/mod_pubsub/pubsub.lib.lua @@ -138,6 +138,30 @@ function _M.get_feature_set(service) return supported_features; end +function _M.handle_disco_info_node(event, service) + local stanza, reply, node = event.stanza, event.reply, event.node; + local ok, ret = service:get_nodes(stanza.attr.from); + local node_obj = ret[node]; + if not ok or not node_obj then + return; + end + event.exists = true; + reply:tag("identity", { category = "pubsub", type = "leaf" }):up(); +end + +function _M.handle_disco_items_node(event, service) + local stanza, reply, node = event.stanza, event.reply, event.node; + local ok, ret = service:get_items(node, stanza.attr.from); + if not ok then + return; + end + + for _, id in ipairs(ret) do + reply:tag("item", { jid = module.host, name = id }):up(); + end + event.exists = true; +end + function _M.handle_pubsub_iq(event, service) local origin, stanza = event.origin, event.stanza; local pubsub_tag = stanza.tags[1]; -- cgit v1.2.3