Software /
code /
prosody
Changeset
11769:071715a18394
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 05 Sep 2021 18:42:44 +0200 |
parents | 11768:aa6ab07544c2 |
children | 11770:d2a9aa1c7ac8 |
files | plugins/mod_pubsub/pubsub.lib.lua |
diffstat | 1 files changed, 9 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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, {