Comparison

mod_mam/mod_mam.lua @ 2513:66a61f48e376

mod_mam: Add comments
author Kim Alvefur <zash@zash.se>
date Mon, 20 Feb 2017 00:09:45 +0100
parent 2512:bc7539ccbde1
child 2515:4cb549622862
comparison
equal deleted inserted replaced
2512:bc7539ccbde1 2513:66a61f48e376
318 if not archive.delete then 318 if not archive.delete then
319 module:log("error", "archive_expires_after set but mod_%s does not support deleting", archive._provided_by); 319 module:log("error", "archive_expires_after set but mod_%s does not support deleting", archive._provided_by);
320 return false; 320 return false;
321 end 321 end
322 322
323 -- Set of known users to do message expiry for
324 -- Populated either below or when new messages are added
323 cleanup = {}; 325 cleanup = {};
324 326
327 -- Iterating over users is not supported by all authentication modules
328 -- Catch and ignore error if not supported
325 pcall(function () 329 pcall(function ()
330 -- If this works, then we schedule cleanup for all known users on startup
326 for user in um.users(module.host) do 331 for user in um.users(module.host) do
327 cleanup[user] = true; 332 cleanup[user] = true;
328 end 333 end
329 end); 334 end);
330 335
336 -- At odd intervals, delete old messages for one user
331 module:add_timer(math.random(10, 60), function() 337 module:add_timer(math.random(10, 60), function()
332 local user = next(cleanup); 338 local user = next(cleanup);
333 if user then 339 if user then
334 module:log("debug", "Removing old messages for user %q", user); 340 module:log("debug", "Removing old messages for user %q", user);
335 local ok, err = archive:delete(user, { ["end"] = os.time() - cleanup_after; }) 341 local ok, err = archive:delete(user, { ["end"] = os.time() - cleanup_after; })