# HG changeset patch # User Kim Alvefur # Date 1674316483 -3600 # Node ID cc86d77481fc24bb610fce425f951cd94adf2b5b # Parent 101c758428aa7f6b3b5b60bd9a0e12345702c1b3 mod_mam,mod_muc_mam: Minimize differences (reorder, copy some comments) Should have no functional difference, but makes it easier keeping mod_mam and mod_muc_mam in sync. diff -r 101c758428aa -r cc86d77481fc plugins/mod_mam/mod_mam.lua --- a/plugins/mod_mam/mod_mam.lua Thu Jan 19 20:59:28 2023 +0100 +++ b/plugins/mod_mam/mod_mam.lua Sat Jan 21 16:54:43 2023 +0100 @@ -138,9 +138,14 @@ local qset = rsm.get(query); local qmax = m_min(qset and qset.max or default_max_items, max_max_items); local reverse = qset and qset.before or false; + local before, after = qset and qset.before or qbefore, qset and qset.after or qafter; if type(before) ~= "string" then before = nil; end + -- A reverse query needs to be flipped + local flip = reverse; + -- A flip-page query needs to be the opposite of that. + if query:get_child("flip-page") then flip = not flip end module:log("debug", "Archive query by %s id=%s with=%s when=%s...%s rsm=%q", origin.username, @@ -150,11 +155,6 @@ qend and timestamp(qend) or "", qset); - -- A reverse query needs to be flipped - local flip = reverse; - -- A flip-page query needs to be the opposite of that. - if query:get_child("flip-page") then flip = not flip end - -- Load all the data! local data, err = archive:find(origin.username, { start = qstart; ["end"] = qend; -- Time range diff -r 101c758428aa -r cc86d77481fc plugins/mod_muc_mam.lua --- a/plugins/mod_muc_mam.lua Thu Jan 19 20:59:28 2023 +0100 +++ b/plugins/mod_muc_mam.lua Sat Jan 21 16:54:43 2023 +0100 @@ -112,7 +112,7 @@ -- Serve form module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) local origin, stanza = event.origin, event.stanza; - origin.send(st.reply(stanza):tag("query", { xmlns = xmlns_mam }):add_child(query_form:form())); + origin.send(st.reply(stanza):query(xmlns_mam):add_child(query_form:form())); return true; end); @@ -172,6 +172,7 @@ local before, after = qset and qset.before or qbefore, qset and qset.after or qafter; if type(before) ~= "string" then before = nil; end + -- A reverse query needs to be flipped local flip = reverse; -- A flip-page query needs to be the opposite of that. @@ -187,11 +188,12 @@ -- Load all the data! local data, err = archive:find(room_node, { start = qstart; ["end"] = qend; -- Time range + with = "message qmax then + -- We requested qmax+1 items. If that many items are retrieved then + -- there are more results to page through, so: complete = nil; break; end @@ -259,7 +263,6 @@ first, last = last, first; end - origin.send(st.reply(stanza) :tag("fin", { xmlns = xmlns_mam, complete = complete }) :add_child(rsm.generate {