236 -- We store chat messages or normal messages that have a body |
236 -- We store chat messages or normal messages that have a body |
237 if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then |
237 if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then |
238 log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); |
238 log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); |
239 return; |
239 return; |
240 end |
240 end |
|
241 |
241 -- or if hints suggest we shouldn't |
242 -- or if hints suggest we shouldn't |
242 if stanza:get_child("no-permanent-storage", "urn:xmpp:hints") -- The XEP needs to decide on "store" or "storage" |
243 if stanza:get_child("no-permanent-storage", "urn:xmpp:hints") -- The XEP needs to decide on "store" or "storage" |
243 or stanza:get_child("no-permanent-store", "urn:xmpp:hints") |
244 or stanza:get_child("no-permanent-store", "urn:xmpp:hints") |
244 or stanza:get_child("no-storage", "urn:xmpp:hints") |
245 or stanza:get_child("no-storage", "urn:xmpp:hints") |
245 or stanza:get_child("no-store", "urn:xmpp:hints") then |
246 or stanza:get_child("no-store", "urn:xmpp:hints") then |
289 if not archive.delete then |
290 if not archive.delete then |
290 module:log("error", "archive_expires_after set but mod_%s does not support deleting", archive._provided_by); |
291 module:log("error", "archive_expires_after set but mod_%s does not support deleting", archive._provided_by); |
291 return false; |
292 return false; |
292 end |
293 end |
293 |
294 |
|
295 -- Set of known users to do message expiry for |
|
296 -- Populated either below or when new messages are added |
294 cleanup = {}; |
297 cleanup = {}; |
295 |
298 |
|
299 -- Iterating over users is not supported by all authentication modules |
|
300 -- Catch and ignore error if not supported |
296 pcall(function () |
301 pcall(function () |
|
302 -- If this works, then we schedule cleanup for all known known |
297 for user in um.users(module.host) do |
303 for user in um.users(module.host) do |
298 cleanup[user] = true; |
304 cleanup[user] = true; |
299 end |
305 end |
300 end); |
306 end); |
301 |
307 |
|
308 -- At odd intervals, delete old messages for one user |
302 module:add_timer(math.random(10, 60), function() |
309 module:add_timer(math.random(10, 60), function() |
303 local user = next(cleanup); |
310 local user = next(cleanup); |
304 if user then |
311 if user then |
305 module:log("debug", "Removing old messages for user %q", user); |
312 module:log("debug", "Removing old messages for user %q", user); |
306 local ok, err = archive:delete(user, { ["end"] = os.time() - cleanup_after; }) |
313 local ok, err = archive:delete(user, { ["end"] = os.time() - cleanup_after; }) |