Mercurial > prosody-hg
comparison plugins/mod_mam/mod_mam.lua @ 12977:74b9e05af71e
plugins: Prefix module imports with prosody namespace
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 24 Mar 2023 13:15:28 +0100 |
| parents | 38b3cd292ee5 |
| children | e732f9dfdfc8 |
comparison
equal
deleted
inserted
replaced
| 12976:a187600ec7d6 | 12977:74b9e05af71e |
|---|---|
| 13 local xmlns_mam_ext = "urn:xmpp:mam:2#extended"; | 13 local xmlns_mam_ext = "urn:xmpp:mam:2#extended"; |
| 14 local xmlns_delay = "urn:xmpp:delay"; | 14 local xmlns_delay = "urn:xmpp:delay"; |
| 15 local xmlns_forward = "urn:xmpp:forward:0"; | 15 local xmlns_forward = "urn:xmpp:forward:0"; |
| 16 local xmlns_st_id = "urn:xmpp:sid:0"; | 16 local xmlns_st_id = "urn:xmpp:sid:0"; |
| 17 | 17 |
| 18 local um = require "core.usermanager"; | 18 local um = require "prosody.core.usermanager"; |
| 19 local st = require "util.stanza"; | 19 local st = require "prosody.util.stanza"; |
| 20 local rsm = require "util.rsm"; | 20 local rsm = require "prosody.util.rsm"; |
| 21 local get_prefs = module:require"mamprefs".get; | 21 local get_prefs = module:require"mamprefs".get; |
| 22 local set_prefs = module:require"mamprefs".set; | 22 local set_prefs = module:require"mamprefs".set; |
| 23 local prefs_to_stanza = module:require"mamprefsxml".tostanza; | 23 local prefs_to_stanza = module:require"mamprefsxml".tostanza; |
| 24 local prefs_from_stanza = module:require"mamprefsxml".fromstanza; | 24 local prefs_from_stanza = module:require"mamprefsxml".fromstanza; |
| 25 local jid_bare = require "util.jid".bare; | 25 local jid_bare = require "prosody.util.jid".bare; |
| 26 local jid_split = require "util.jid".split; | 26 local jid_split = require "prosody.util.jid".split; |
| 27 local jid_resource = require "util.jid".resource; | 27 local jid_resource = require "prosody.util.jid".resource; |
| 28 local jid_prepped_split = require "util.jid".prepped_split; | 28 local jid_prepped_split = require "prosody.util.jid".prepped_split; |
| 29 local dataform = require "util.dataforms".new; | 29 local dataform = require "prosody.util.dataforms".new; |
| 30 local get_form_type = require "util.dataforms".get_type; | 30 local get_form_type = require "prosody.util.dataforms".get_type; |
| 31 local host = module.host; | 31 local host = module.host; |
| 32 | 32 |
| 33 local rm_load_roster = require "core.rostermanager".load_roster; | 33 local rm_load_roster = require "prosody.core.rostermanager".load_roster; |
| 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 "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("prosody.util.datetime", "datetime", "date"); |
| 40 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); |
| 41 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" }); |
| 42 | 42 |
| 43 local archive_store = module:get_option_string("archive_store", "archive"); | 43 local archive_store = module:get_option_string("archive_store", "archive"); |
| 44 local archive = module:open_store(archive_store, "archive"); | 44 local archive = module:open_store(archive_store, "archive"); |
| 530 -- For each day, store a set of users that have new messages. To expire | 530 -- For each day, store a set of users that have new messages. To expire |
| 531 -- messages, we collect the union of sets of users from dates that fall | 531 -- messages, we collect the union of sets of users from dates that fall |
| 532 -- outside the cleanup range. | 532 -- outside the cleanup range. |
| 533 | 533 |
| 534 if not (archive.caps and archive.caps.wildcard_delete) then | 534 if not (archive.caps and archive.caps.wildcard_delete) then |
| 535 local last_date = require "util.cache".new(module:get_option_number("archive_cleanup_date_cache_size", 1000)); | 535 local last_date = require "prosody.util.cache".new(module:get_option_number("archive_cleanup_date_cache_size", 1000)); |
| 536 function schedule_cleanup(username, date) | 536 function schedule_cleanup(username, date) |
| 537 date = date or datestamp(); | 537 date = date or datestamp(); |
| 538 if last_date:get(username) == date then return end | 538 if last_date:get(username) == date then return end |
| 539 local ok = cleanup_map:set(date, username, true); | 539 local ok = cleanup_map:set(date, username, true); |
| 540 if ok then | 540 if ok then |
| 543 end | 543 end |
| 544 end | 544 end |
| 545 | 545 |
| 546 local cleanup_time = module:measure("cleanup", "times"); | 546 local cleanup_time = module:measure("cleanup", "times"); |
| 547 | 547 |
| 548 local async = require "util.async"; | 548 local async = require "prosody.util.async"; |
| 549 module:daily("Remove expired messages", function () | 549 module:daily("Remove expired messages", function () |
| 550 local cleanup_done = cleanup_time(); | 550 local cleanup_done = cleanup_time(); |
| 551 | 551 |
| 552 if archive.caps and archive.caps.wildcard_delete then | 552 if archive.caps and archive.caps.wildcard_delete then |
| 553 local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after }) | 553 local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after }) |
