diff options
author | Kim Alvefur <zash@zash.se> | 2018-07-06 18:00:50 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2018-07-06 18:00:50 +0200 |
commit | eb28cd503ff82b386824e3329a1a6a0d0d1f10e3 (patch) | |
tree | 450f33edea7b64563c14a4f538fbacc1e98a5219 /plugins | |
parent | e0e83371bfd75c92db4dc8cb82f5572eae42cc85 (diff) | |
download | prosody-eb28cd503ff82b386824e3329a1a6a0d0d1f10e3.tar.gz prosody-eb28cd503ff82b386824e3329a1a6a0d0d1f10e3.zip |
mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mod_pubsub/mod_pubsub.lua | 19 | ||||
-rw-r--r-- | plugins/mod_pubsub/pubsub.lib.lua | 24 |
2 files changed, 26 insertions, 17 deletions
diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua index 9e9656c1..c97e9d98 100644 --- a/plugins/mod_pubsub/mod_pubsub.lua +++ b/plugins/mod_pubsub/mod_pubsub.lua @@ -88,26 +88,11 @@ local function add_disco_features_from_service(service) --luacheck: ignore 431/s end module:hook("host-disco-info-node", function (event) - local stanza, reply, node = event.stanza, event.reply, event.node; - local ok, ret = service:get_nodes(stanza.attr.from); - if not ok or not ret[node] then - return; - end - event.exists = true; - reply:tag("identity", { category = "pubsub", type = "leaf" }); + return lib_pubsub.handle_disco_info_node(event, service); end); module:hook("host-disco-items-node", function (event) - 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; + return lib_pubsub.handle_disco_items_node(event, service); end); 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]; |