aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_muc_mam.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_muc_mam.lua')
-rw-r--r--plugins/mod_muc_mam.lua23
1 files changed, 20 insertions, 3 deletions
diff --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua
index c2026371..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
@@ -109,10 +110,20 @@ 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;
- 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 +183,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 +199,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<groupchat";
limit = qmax + 1;
before = before; after = after;
ids = qids;
reverse = reverse;
- with = "message<groupchat";
+ total = use_total or qmax == 0;
});
if not data then
@@ -216,6 +229,8 @@ module:hook("iq-set/bare/"..xmlns_mam..":query", function(event)
for id, item, when in data do
count = count + 1;
if count > 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 +274,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 {
@@ -551,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