Software /
code /
prosody
Comparison
plugins/mod_mam/mod_mam.lua @ 13055:e732f9dfdfc8
mod_mam: port to use util.human.io.parse_duration
Updated by Zash, the original patch by Jonas had put the duration
parsing function in util.datetime but MattJ later did the same thing but
differently in f4d7fe919969
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Thu, 28 Apr 2022 20:38:40 +0200 |
parent | 12977:74b9e05af71e |
child | 13165:9c13c11b199d |
comparison
equal
deleted
inserted
replaced
13054:f4d7fe919969 | 13055:e732f9dfdfc8 |
---|---|
34 | 34 |
35 local is_stanza = st.is_stanza; | 35 local is_stanza = st.is_stanza; |
36 local tostring = tostring; | 36 local tostring = tostring; |
37 local time_now = require "prosody.util.time".now; | 37 local time_now = require "prosody.util.time".now; |
38 local m_min = math.min; | 38 local m_min = math.min; |
39 local timestamp, datestamp = import("prosody.util.datetime", "datetime", "date"); | 39 local timestamp, datestamp = import( "util.datetime", "datetime", "date"); |
40 local parse_duration = require "util.human.io".parse_duration; | |
40 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); | 41 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); |
41 local strip_tags = module:get_option_set("dont_archive_namespaces", { "http://jabber.org/protocol/chatstates" }); | 42 local strip_tags = module:get_option_set("dont_archive_namespaces", { "http://jabber.org/protocol/chatstates" }); |
42 | 43 |
43 local archive_store = module:get_option_string("archive_store", "archive"); | 44 local archive_store = module:get_option_string("archive_store", "archive"); |
44 local archive = module:open_store(archive_store, "archive"); | 45 local archive = module:open_store(archive_store, "archive"); |
508 | 509 |
509 if cleanup_after ~= "never" then | 510 if cleanup_after ~= "never" then |
510 local cleanup_storage = module:open_store("archive_cleanup"); | 511 local cleanup_storage = module:open_store("archive_cleanup"); |
511 local cleanup_map = module:open_store("archive_cleanup", "map"); | 512 local cleanup_map = module:open_store("archive_cleanup", "map"); |
512 | 513 |
513 local day = 86400; | 514 local cleanup_after_seconds, parse_err = parse_duration(cleanup_after); |
514 local multipliers = { d = day, w = day * 7, m = 31 * day, y = 365.2425 * day }; | 515 if parse_err ~= nil then |
515 local n, m = cleanup_after:lower():match("(%d+)%s*([dwmy]?)"); | 516 module:log("error", "Could not parse archive_expires_after string %q: %s", cleanup_after, parse_err); |
516 if not n then | |
517 module:log("error", "Could not parse archive_expires_after string %q", cleanup_after); | |
518 return false; | 517 return false; |
519 end | 518 end |
520 | 519 cleanup_after = cleanup_after_seconds; |
521 cleanup_after = tonumber(n) * ( multipliers[m] or 1 ); | |
522 | 520 |
523 module:log("debug", "archive_expires_after = %d -- in seconds", cleanup_after); | 521 module:log("debug", "archive_expires_after = %d -- in seconds", cleanup_after); |
524 | 522 |
525 if not archive.delete then | 523 if not archive.delete then |
526 module:log("error", "archive_expires_after set but mod_%s does not support deleting", archive._provided_by); | 524 module:log("error", "archive_expires_after set but mod_%s does not support deleting", archive._provided_by); |