From 4830568435f6f07e3c3241861cc901adc6b53977 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 21 Jan 2023 16:54:43 +0100 Subject: 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. --- plugins/mod_mam/mod_mam.lua | 10 +++++----- plugins/mod_muc_mam.lua | 9 ++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 50095e2f..bebee812 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -138,9 +138,14 @@ module:hook("iq-set/self/"..xmlns_mam..":query", function(event) 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 @@ module:hook("iq-set/self/"..xmlns_mam..":query", function(event) 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 --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua index c2026371..15780d41 100644 --- a/plugins/mod_muc_mam.lua +++ b/plugins/mod_muc_mam.lua @@ -112,7 +112,7 @@ local query_form = dataform { -- 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 @@ module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) 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 @@ module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) -- 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 @@ module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) first, last = last, first; end - origin.send(st.reply(stanza) :tag("fin", { xmlns = xmlns_mam, complete = complete }) :add_child(rsm.generate { -- cgit v1.2.3 From d0321442c91790342601ae3ea62ec2c1831801b4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 21 Jan 2023 17:09:22 +0100 Subject: mod_muc_mam: Add mam#extended form fields #1796 (Thanks Rain) Oversight in cabb022f31c0 --- plugins/mod_muc_mam.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'plugins') diff --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua index 15780d41..6195b081 100644 --- a/plugins/mod_muc_mam.lua +++ b/plugins/mod_muc_mam.lua @@ -109,6 +109,16 @@ local query_form = dataform { { name = "end"; type = "text-single"; datatype = "xs:dateTime" }; }; +if archive.caps and archive.caps.full_id_range then + table.insert(query_form, { name = "before-id"; type = "text-single"; }); + table.insert(query_form, { name = "after-id"; type = "text-single"; }); +end + +if archive.caps and archive.caps.ids then + table.insert(query_form, { name = "ids"; type = "list-multi"; }); +end + + -- Serve form module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) local origin, stanza = event.origin, event.stanza; -- cgit v1.2.3 From 81fd03356fbb451c5a7089a2520ebb7fbf6caf30 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 21 Jan 2023 17:14:55 +0100 Subject: mod_muc_mam: Copy "include total" behavior from mod_mam Not sure why this was missing from MUC MAM, it already had some of the code for dealing with it. --- plugins/mod_muc_mam.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua index 6195b081..1c34b8af 100644 --- a/plugins/mod_muc_mam.lua +++ b/plugins/mod_muc_mam.lua @@ -67,6 +67,7 @@ if archive.name == "null" or not archive.find then module:log("info", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information"); return false; end +local use_total = module:get_option_boolean("muc_log_include_total", true); local function archiving_enabled(room) if log_all_rooms then @@ -203,7 +204,7 @@ module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) before = before; after = after; ids = qids; reverse = reverse; - total = qmax == 0; + total = use_total or qmax == 0; }); if not data then @@ -564,4 +565,7 @@ if cleanup_after ~= "never" then else module:log("debug", "Archive expiry disabled"); + -- Don't ask the backend to count the potentially unbounded number of items, + -- it'll get slow. + use_total = module:get_option_boolean("mam_include_total", false); end -- cgit v1.2.3