Mercurial > prosody-hg
comparison plugins/mod_mam/mod_mam.lua @ 13209:c8d949cf6b09
plugins: Switch to :get_option_period() for time range options
Improves readability ("1 day" vs 86400) and centralizes validation.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 16 Jul 2023 20:49:33 +0200 |
| parents | 9c13c11b199d |
| children | 50324f66ca2a |
comparison
equal
deleted
inserted
replaced
| 13208:a7c6ea1c5308 | 13209:c8d949cf6b09 |
|---|---|
| 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( "util.datetime", "datetime", "date"); | 39 local timestamp, datestamp = import( "util.datetime", "datetime", "date"); |
| 40 local parse_duration = require "prosody.util.human.io".parse_duration; | |
| 41 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); | 40 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); |
| 42 local strip_tags = module:get_option_set("dont_archive_namespaces", { "http://jabber.org/protocol/chatstates" }); | 41 local strip_tags = module:get_option_set("dont_archive_namespaces", { "http://jabber.org/protocol/chatstates" }); |
| 43 | 42 |
| 44 local archive_store = module:get_option_string("archive_store", "archive"); | 43 local archive_store = module:get_option_string("archive_store", "archive"); |
| 45 local archive = module:open_store(archive_store, "archive"); | 44 local archive = module:open_store(archive_store, "archive"); |
| 46 | 45 |
| 47 local cleanup_after = module:get_option_string("archive_expires_after", "1w"); | 46 local cleanup_after = module:get_option_period("archive_expires_after", "1w"); |
| 48 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000); | 47 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000); |
| 49 local archive_truncate = math.floor(archive_item_limit * 0.99); | 48 local archive_truncate = math.floor(archive_item_limit * 0.99); |
| 50 | 49 |
| 51 if not archive.find then | 50 if not archive.find then |
| 52 error("mod_"..(archive._provided_by or archive.name and "storage_"..archive.name).." does not support archiving\n" | 51 error("mod_"..(archive._provided_by or archive.name and "storage_"..archive.name).." does not support archiving\n" |
| 508 end); | 507 end); |
| 509 | 508 |
| 510 if cleanup_after ~= "never" then | 509 if cleanup_after ~= "never" then |
| 511 local cleanup_storage = module:open_store("archive_cleanup"); | 510 local cleanup_storage = module:open_store("archive_cleanup"); |
| 512 local cleanup_map = module:open_store("archive_cleanup", "map"); | 511 local cleanup_map = module:open_store("archive_cleanup", "map"); |
| 513 | |
| 514 local cleanup_after_seconds, parse_err = parse_duration(cleanup_after); | |
| 515 if parse_err ~= nil then | |
| 516 module:log("error", "Could not parse archive_expires_after string %q: %s", cleanup_after, parse_err); | |
| 517 return false; | |
| 518 end | |
| 519 cleanup_after = cleanup_after_seconds; | |
| 520 | 512 |
| 521 module:log("debug", "archive_expires_after = %d -- in seconds", cleanup_after); | 513 module:log("debug", "archive_expires_after = %d -- in seconds", cleanup_after); |
| 522 | 514 |
| 523 if not archive.delete then | 515 if not archive.delete then |
| 524 module:log("error", "archive_expires_after set but mod_%s does not support deleting", archive._provided_by); | 516 module:log("error", "archive_expires_after set but mod_%s does not support deleting", archive._provided_by); |
