diff options
author | Kim Alvefur <zash@zash.se> | 2019-01-28 01:41:01 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-01-28 01:41:01 +0100 |
commit | da56744645d0fc15fe0b106d4ff771b44393bd8e (patch) | |
tree | d0043b4eea17b54199e2e96ce9383933a6f15fa5 /util | |
parent | d0d8bf923764d1d6482184d4bf0593488ffbb32a (diff) | |
download | prosody-da56744645d0fc15fe0b106d4ff771b44393bd8e.tar.gz prosody-da56744645d0fc15fe0b106d4ff771b44393bd8e.zip |
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Diffstat (limited to 'util')
-rw-r--r-- | util/pubsub.lua | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/util/pubsub.lua b/util/pubsub.lua index 47e526a7..a53e8b95 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -600,7 +600,7 @@ function service:purge(node, actor, notify) --> ok, err return true end -function service:get_items(node, actor, id) --> (true, { id, [id] = node }) or (false, err) +function service:get_items(node, actor, ids) --> (true, { id, [id] = node }) or (false, err) -- Access checking if not self:may(node, actor, "get_items") then return false, "forbidden"; @@ -610,20 +610,25 @@ function service:get_items(node, actor, id) --> (true, { id, [id] = node }) or ( if not node_obj then return false, "item-not-found"; end - if id then -- Restrict results to a single specific item - local with_id = self.data[node]:get(id); - if not with_id then - return true, { }; + if type(ids) == "string" then -- COMPAT see #1305 + ids = { ids }; + end + local data = {}; + if ids then + for _, key in ipairs(ids) do + local value = self.data[node]:get(key); + if value then + data[#data+1] = key; + data[key] = value; + end end - return true, { id, [id] = with_id }; else - local data = {} for key, value in self.data[node]:items() do data[#data+1] = key; data[key] = value; end - return true, data; end + return true, data; end function service:get_last_item(node, actor) --> (true, id, node) or (false, err) |