Comparison

plugins/mod_pubsub/pubsub.lib.lua @ 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
parent 11768:aa6ab07544c2
child 11785:b1381e302cab
comparison
equal deleted inserted replaced
11768:aa6ab07544c2 11769:071715a18394
334 end 334 end
335 335
336 local expose_publisher = service.config.expose_publisher; 336 local expose_publisher = service.config.expose_publisher;
337 337
338 local data = st.stanza("items", { node = node }); 338 local data = st.stanza("items", { node = node });
339 for _, id in ipairs(results) do 339 local iter, v, i = ipairs(results);
340 if not requested_items then
341 -- XXX Hack to preserve order of explicitly requested items.
342 iter, v, i = it.reverse(iter, v, i);
343 end
344
345 for _, id in iter, v, i do
340 local item = results[id]; 346 local item = results[id];
341 if not expose_publisher then 347 if not expose_publisher then
342 item = st.clone(item); 348 item = st.clone(item);
343 item.attr.publisher = nil; 349 item.attr.publisher = nil;
344 end 350 end
827 if not data then 833 if not data then
828 module:log("error", "Unable to get items: %s", err); 834 module:log("error", "Unable to get items: %s", err);
829 return true; 835 return true;
830 end 836 end
831 module:log("debug", "Listed items %s", data); 837 module:log("debug", "Listed items %s", data);
832 return it.reverse(function() 838 return function()
833 -- luacheck: ignore 211/when 839 -- luacheck: ignore 211/when
834 local id, payload, when, publisher = data(); 840 local id, payload, when, publisher = data();
835 if id == nil then 841 if id == nil then
836 return; 842 return;
837 end 843 end
838 local item = create_encapsulating_item(id, payload, publisher); 844 local item = create_encapsulating_item(id, payload, publisher);
839 return id, item; 845 return id, item;
840 end); 846 end;
841 end 847 end
842 function get_set:get(key) -- luacheck: ignore 212/self 848 function get_set:get(key) -- luacheck: ignore 212/self
843 local data, err = archive:find(user, { 849 local data, err = archive:find(user, {
844 key = key; 850 key = key;
845 -- Get the last item with that key, if the archive doesn't deduplicate 851 -- Get the last item with that key, if the archive doesn't deduplicate