aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pubsub/pubsub.lib.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-09-05 18:42:44 +0200
committerKim Alvefur <zash@zash.se>2021-09-05 18:42:44 +0200
commit3b0eb07e5db79a12e56f8248f9d788504f3926de (patch)
treef8048d8919dc5412c90d2810e867c3076fc01b5c /plugins/mod_pubsub/pubsub.lib.lua
parent22060f15ccd6851e77dd0cd38efaecb91bd0d623 (diff)
downloadprosody-3b0eb07e5db79a12e56f8248f9d788504f3926de.tar.gz
prosody-3b0eb07e5db79a12e56f8248f9d788504f3926de.zip
mod_pubsub: Move reversal of item order in <items>
Examples in XEP-0060 suggest that items should be listed in chronological order, but we get them from the archive in reverse order. However when requesting specific items by id the results keep that order and we don't want to flip it again. At some point it would likely be best to use the archive API directly instead of this util.cache-compatible wrapper.
Diffstat (limited to 'plugins/mod_pubsub/pubsub.lib.lua')
-rw-r--r--plugins/mod_pubsub/pubsub.lib.lua12
1 files changed, 9 insertions, 3 deletions
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index 92e210ca..90f7dcb1 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -336,7 +336,13 @@ function handlers.get_items(origin, stanza, items, service)
local expose_publisher = service.config.expose_publisher;
local data = st.stanza("items", { node = node });
- for _, id in ipairs(results) do
+ local iter, v, i = ipairs(results);
+ if not requested_items then
+ -- XXX Hack to preserve order of explicitly requested items.
+ iter, v, i = it.reverse(iter, v, i);
+ end
+
+ for _, id in iter, v, i do
local item = results[id];
if not expose_publisher then
item = st.clone(item);
@@ -829,7 +835,7 @@ local function archive_itemstore(archive, max_items, user, node)
return true;
end
module:log("debug", "Listed items %s", data);
- return it.reverse(function()
+ return function()
-- luacheck: ignore 211/when
local id, payload, when, publisher = data();
if id == nil then
@@ -837,7 +843,7 @@ local function archive_itemstore(archive, max_items, user, node)
end
local item = create_encapsulating_item(id, payload, publisher);
return id, item;
- end);
+ end;
end
function get_set:get(key) -- luacheck: ignore 212/self
local data, err = archive:find(user, {