aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-07-13 04:41:59 +0200
committerKim Alvefur <zash@zash.se>2018-07-13 04:41:59 +0200
commitfc5c354891511953236276cfffa4d4d07c278c4d (patch)
treecbbfd844736268399776346625ff0b21fe2e559e
parent334655c4592807ed1bd4e02551489df1a24dfcda (diff)
downloadprosody-fc5c354891511953236276cfffa4d4d07c278c4d.tar.gz
prosody-fc5c354891511953236276cfffa4d4d07c278c4d.zip
util.pubsub: Support for returning *all* subscriptions
-rw-r--r--util/pubsub.lua52
1 files changed, 31 insertions, 21 deletions
diff --git a/util/pubsub.lua b/util/pubsub.lua
index 74fa2be4..b7f89844 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -458,6 +458,29 @@ function service:get_nodes(actor)
return true, self.nodes;
end
+local function flatten_subscriptions(ret, serv, subs, node, node_obj)
+ for subscribed_jid, subscribed_nodes in pairs(subs) do
+ if node then -- Return only subscriptions to this node
+ if subscribed_nodes[node] then
+ ret[#ret+1] = {
+ node = node;
+ jid = subscribed_jid;
+ subscription = node_obj.subscribers[subscribed_jid];
+ };
+ end
+ else -- Return subscriptions to all nodes
+ local nodes = serv.nodes;
+ for subscribed_node in pairs(subscribed_nodes) do
+ ret[#ret+1] = {
+ node = subscribed_node;
+ jid = subscribed_jid;
+ subscription = nodes[subscribed_node].subscribers[subscribed_jid];
+ };
+ end
+ end
+ end
+end
+
function service:get_subscriptions(node, actor, jid)
-- Access checking
local cap;
@@ -477,32 +500,19 @@ function service:get_subscriptions(node, actor, jid)
return false, "item-not-found";
end
end
+ local ret = {};
+ if jid == nil then
+ for _, subs in pairs(self.subscriptions) do
+ flatten_subscriptions(ret, self, subs, node, node_obj)
+ end
+ return true, ret;
+ end
local normal_jid = self.config.normalize_jid(jid);
local subs = self.subscriptions[normal_jid];
-- We return the subscription object from the node to save
-- a get_subscription() call for each node.
- local ret = {};
if subs then
- for subscribed_jid, subscribed_nodes in pairs(subs) do
- if node then -- Return only subscriptions to this node
- if subscribed_nodes[node] then
- ret[#ret+1] = {
- node = node;
- jid = subscribed_jid;
- subscription = node_obj.subscribers[subscribed_jid];
- };
- end
- else -- Return subscriptions to all nodes
- local nodes = self.nodes;
- for subscribed_node in pairs(subscribed_nodes) do
- ret[#ret+1] = {
- node = subscribed_node;
- jid = subscribed_jid;
- subscription = nodes[subscribed_node].subscribers[subscribed_jid];
- };
- end
- end
- end
+ flatten_subscriptions(ret, self, subs, node, node_obj)
end
return true, ret;
end