From 3b0eb07e5db79a12e56f8248f9d788504f3926de Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 5 Sep 2021 18:42:44 +0200 Subject: mod_pubsub: Move reversal of item order in 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. --- plugins/mod_pubsub/pubsub.lib.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'plugins/mod_pubsub') 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, { -- cgit v1.2.3