Software /
code /
prosody
Changeset
8980:4d2738b99b07
mod_pubsub: Move service discovery to pubsub.lib to allow reuse
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 06 Jul 2018 18:00:50 +0200 |
parents | 8979:6897b2e18bdf |
children | 8981:b6cb0a8f75b1 |
files | plugins/mod_pubsub/mod_pubsub.lua plugins/mod_pubsub/pubsub.lib.lua |
diffstat | 2 files changed, 26 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_pubsub/mod_pubsub.lua Fri Jul 06 16:04:53 2018 +0200 +++ b/plugins/mod_pubsub/mod_pubsub.lua Fri Jul 06 18:00:50 2018 +0200 @@ -88,26 +88,11 @@ 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);
--- a/plugins/mod_pubsub/pubsub.lib.lua Fri Jul 06 16:04:53 2018 +0200 +++ b/plugins/mod_pubsub/pubsub.lib.lua Fri Jul 06 18:00:50 2018 +0200 @@ -138,6 +138,30 @@ 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];