# HG changeset patch # User Kim Alvefur # Date 1689676431 -7200 # Node ID 58083329903d37f8a612969df9c611c3fc403cde # Parent ac44bb7b7064651e4452ef0a8aea080d532cbb9e mod_muc_mam: Use period option method diff -r ac44bb7b7064 -r 58083329903d plugins/mod_muc_mam.lua --- a/plugins/mod_muc_mam.lua Tue Jul 18 12:32:41 2023 +0200 +++ b/plugins/mod_muc_mam.lua Tue Jul 18 12:33:51 2023 +0200 @@ -34,7 +34,7 @@ local timestamp, datestamp = import("prosody.util.datetime", "datetime", "date"); local default_max_items, max_max_items = 20, module:get_option_integer("max_archive_query_results", 50, 0); -local cleanup_after = module:get_option_string("muc_log_expires_after", "1w"); +local cleanup_after = module:get_option_period("muc_log_expires_after", "1w"); local default_history_length = 20; local max_history_length = module:get_option_integer("max_history_messages", math.huge, 0); @@ -397,7 +397,7 @@ local id, err = archive:append(room_node, nil, stored_stanza, time, with); if not id and err == "quota-limit" then - if type(cleanup_after) == "number" then + if cleanup_after ~= math.huge then module:log("debug", "Room '%s' over quota, cleaning archive", room_node); local cleaned = archive:delete(room_node, { ["end"] = (os.time() - cleanup_after); @@ -467,20 +467,10 @@ -- Cleanup -if cleanup_after ~= "never" then +if cleanup_after ~= math.huge then local cleanup_storage = module:open_store("muc_log_cleanup"); local cleanup_map = module:open_store("muc_log_cleanup", "map"); - local day = 86400; - local multipliers = { d = day, w = day * 7, m = 31 * day, y = 365.2425 * day }; - local n, m = cleanup_after:lower():match("(%d+)%s*([dwmy]?)"); - if not n then - module:log("error", "Could not parse muc_log_expires_after string %q", cleanup_after); - return false; - end - - cleanup_after = tonumber(n) * ( multipliers[m] or 1 ); - module:log("debug", "muc_log_expires_after = %d -- in seconds", cleanup_after); if not archive.delete then