changeset 14007:8fb7408ded73

mod_mam: Fire event when a query has been processed This can be used to track queries made by clients. The plan is to use it for smart retention.
author Matthew Wild <mwild1@gmail.com>
date Sat, 06 Dec 2025 17:32:50 +0000
parents 0d162ef4e0c1
children 21126415c8a0
files plugins/mod_mam/mod_mam.lua
diffstat 1 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_mam/mod_mam.lua	Sat Dec 06 17:30:47 2025 +0000
+++ b/plugins/mod_mam/mod_mam.lua	Sat Dec 06 17:32:50 2025 +0000
@@ -190,6 +190,7 @@
 	local first, last;
 	local count = 0;
 	local complete = "true";
+	local oldest, newest;
 	for id, item, when in data do
 		count = count + 1;
 		if count > qmax then
@@ -212,6 +213,13 @@
 		if not first then first = id; end
 		last = id;
 
+		if not newest or when > newest then
+			newest = when;
+		end
+		if not oldest or when < oldest then
+			oldest = when;
+		end
+
 		if flip then
 			results[count] = fwd_st;
 		else
@@ -233,6 +241,15 @@
 			:add_child(rsm.generate {
 				first = first, last = last, count = total }));
 
+	module:fire_event("archive-query-result", {
+		origin = origin;
+		stanza = stanza;
+		first_time = oldest;
+		last_time = newest;
+		first_id = reverse and last or first;
+		last_id = reverse and first or last;
+	});
+
 	-- That's all folks!
 	module:log("debug", "Archive query id=%s completed, %d items returned", qid or stanza.attr.id, complete and count or count - 1);
 	return true;
@@ -589,7 +606,6 @@
 		module:log("info", "Deleted %d expired messages for %d users", sum, num_users);
 		cleanup_done();
 	end);
-
 else
 	module:log("debug", "Archive expiry disabled");
 	-- Don't ask the backend to count the potentially unbounded number of items,