# HG changeset patch # User Kim Alvefur # Date 1630860164 -7200 # Node ID 071715a18394c1c72cd9063fee6b94a11d0def47 # Parent aa6ab07544c2dc2dc5007a14731f2185eb46f858 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. diff -r aa6ab07544c2 -r 071715a18394 plugins/mod_pubsub/pubsub.lib.lua --- a/plugins/mod_pubsub/pubsub.lib.lua Sun Sep 05 16:43:41 2021 +0200 +++ b/plugins/mod_pubsub/pubsub.lib.lua Sun Sep 05 18:42:44 2021 +0200 @@ -336,7 +336,13 @@ 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 @@ 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 @@ 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, {