Software /
code /
prosody
Comparison
plugins/mod_muc_mam.lua @ 13227:58083329903d
mod_muc_mam: Use period option method
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 18 Jul 2023 12:33:51 +0200 |
parent | 13213:50324f66ca2a |
child | 13268:081f8f9b3b81 |
comparison
equal
deleted
inserted
replaced
13226:ac44bb7b7064 | 13227:58083329903d |
---|---|
32 local time_now = require "prosody.util.time".now; | 32 local time_now = require "prosody.util.time".now; |
33 local m_min = math.min; | 33 local m_min = math.min; |
34 local timestamp, datestamp = import("prosody.util.datetime", "datetime", "date"); | 34 local timestamp, datestamp = import("prosody.util.datetime", "datetime", "date"); |
35 local default_max_items, max_max_items = 20, module:get_option_integer("max_archive_query_results", 50, 0); | 35 local default_max_items, max_max_items = 20, module:get_option_integer("max_archive_query_results", 50, 0); |
36 | 36 |
37 local cleanup_after = module:get_option_string("muc_log_expires_after", "1w"); | 37 local cleanup_after = module:get_option_period("muc_log_expires_after", "1w"); |
38 | 38 |
39 local default_history_length = 20; | 39 local default_history_length = 20; |
40 local max_history_length = module:get_option_integer("max_history_messages", math.huge, 0); | 40 local max_history_length = module:get_option_integer("max_history_messages", math.huge, 0); |
41 | 41 |
42 local function get_historylength(room) | 42 local function get_historylength(room) |
395 -- And stash it | 395 -- And stash it |
396 local time = time_now(); | 396 local time = time_now(); |
397 local id, err = archive:append(room_node, nil, stored_stanza, time, with); | 397 local id, err = archive:append(room_node, nil, stored_stanza, time, with); |
398 | 398 |
399 if not id and err == "quota-limit" then | 399 if not id and err == "quota-limit" then |
400 if type(cleanup_after) == "number" then | 400 if cleanup_after ~= math.huge then |
401 module:log("debug", "Room '%s' over quota, cleaning archive", room_node); | 401 module:log("debug", "Room '%s' over quota, cleaning archive", room_node); |
402 local cleaned = archive:delete(room_node, { | 402 local cleaned = archive:delete(room_node, { |
403 ["end"] = (os.time() - cleanup_after); | 403 ["end"] = (os.time() - cleanup_after); |
404 }); | 404 }); |
405 if cleaned then | 405 if cleaned then |
465 event.reply:tag("feature", {var=xmlns_st_id}):up(); | 465 event.reply:tag("feature", {var=xmlns_st_id}):up(); |
466 end); | 466 end); |
467 | 467 |
468 -- Cleanup | 468 -- Cleanup |
469 | 469 |
470 if cleanup_after ~= "never" then | 470 if cleanup_after ~= math.huge then |
471 local cleanup_storage = module:open_store("muc_log_cleanup"); | 471 local cleanup_storage = module:open_store("muc_log_cleanup"); |
472 local cleanup_map = module:open_store("muc_log_cleanup", "map"); | 472 local cleanup_map = module:open_store("muc_log_cleanup", "map"); |
473 | |
474 local day = 86400; | |
475 local multipliers = { d = day, w = day * 7, m = 31 * day, y = 365.2425 * day }; | |
476 local n, m = cleanup_after:lower():match("(%d+)%s*([dwmy]?)"); | |
477 if not n then | |
478 module:log("error", "Could not parse muc_log_expires_after string %q", cleanup_after); | |
479 return false; | |
480 end | |
481 | |
482 cleanup_after = tonumber(n) * ( multipliers[m] or 1 ); | |
483 | 473 |
484 module:log("debug", "muc_log_expires_after = %d -- in seconds", cleanup_after); | 474 module:log("debug", "muc_log_expires_after = %d -- in seconds", cleanup_after); |
485 | 475 |
486 if not archive.delete then | 476 if not archive.delete then |
487 module:log("error", "muc_log_expires_after set but mod_%s does not support deleting", archive._provided_by); | 477 module:log("error", "muc_log_expires_after set but mod_%s does not support deleting", archive._provided_by); |