comparison plugins/mod_mam/mod_mam.lua @ 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 b6d857435de1
children f5d415d54064
comparison
equal deleted inserted replaced
14006:0d162ef4e0c1 14007:8fb7408ded73
188 188
189 -- Wrap it in stuff and deliver 189 -- Wrap it in stuff and deliver
190 local first, last; 190 local first, last;
191 local count = 0; 191 local count = 0;
192 local complete = "true"; 192 local complete = "true";
193 local oldest, newest;
193 for id, item, when in data do 194 for id, item, when in data do
194 count = count + 1; 195 count = count + 1;
195 if count > qmax then 196 if count > qmax then
196 -- We requested qmax+1 items. If that many items are retrieved then 197 -- We requested qmax+1 items. If that many items are retrieved then
197 -- there are more results to page through, so: 198 -- there are more results to page through, so:
210 fwd_st:add_child(item); 211 fwd_st:add_child(item);
211 212
212 if not first then first = id; end 213 if not first then first = id; end
213 last = id; 214 last = id;
214 215
216 if not newest or when > newest then
217 newest = when;
218 end
219 if not oldest or when < oldest then
220 oldest = when;
221 end
222
215 if flip then 223 if flip then
216 results[count] = fwd_st; 224 results[count] = fwd_st;
217 else 225 else
218 origin.send(fwd_st); 226 origin.send(fwd_st);
219 end 227 end
230 238
231 origin.send(st.reply(stanza) 239 origin.send(st.reply(stanza)
232 :tag("fin", { xmlns = xmlns_mam, complete = complete }) 240 :tag("fin", { xmlns = xmlns_mam, complete = complete })
233 :add_child(rsm.generate { 241 :add_child(rsm.generate {
234 first = first, last = last, count = total })); 242 first = first, last = last, count = total }));
243
244 module:fire_event("archive-query-result", {
245 origin = origin;
246 stanza = stanza;
247 first_time = oldest;
248 last_time = newest;
249 first_id = reverse and last or first;
250 last_id = reverse and first or last;
251 });
235 252
236 -- That's all folks! 253 -- That's all folks!
237 module:log("debug", "Archive query id=%s completed, %d items returned", qid or stanza.attr.id, complete and count or count - 1); 254 module:log("debug", "Archive query id=%s completed, %d items returned", qid or stanza.attr.id, complete and count or count - 1);
238 return true; 255 return true;
239 end); 256 end);
587 async.sleep(0.1); 604 async.sleep(0.1);
588 end 605 end
589 module:log("info", "Deleted %d expired messages for %d users", sum, num_users); 606 module:log("info", "Deleted %d expired messages for %d users", sum, num_users);
590 cleanup_done(); 607 cleanup_done();
591 end); 608 end);
592
593 else 609 else
594 module:log("debug", "Archive expiry disabled"); 610 module:log("debug", "Archive expiry disabled");
595 -- Don't ask the backend to count the potentially unbounded number of items, 611 -- Don't ask the backend to count the potentially unbounded number of items,
596 -- it'll get slow. 612 -- it'll get slow.
597 use_total = module:get_option_boolean("mam_include_total", false); 613 use_total = module:get_option_boolean("mam_include_total", false);