Mercurial > prosody-hg
annotate plugins/mod_mam/mod_mam.lua @ 14229:ce31fdde0ad1 default tip
net.unbound: Simplify conditional
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 13 Jun 2026 11:35:18 +0200 |
| parents | f5d415d54064 |
| children |
| rev | line source |
|---|---|
|
7851
80ee0d9cd56f
mod_mam: Normalize copyright headers
Kim Alvefur <zash@zash.se>
parents:
7850
diff
changeset
|
1 -- Prosody IM |
|
80ee0d9cd56f
mod_mam: Normalize copyright headers
Kim Alvefur <zash@zash.se>
parents:
7850
diff
changeset
|
2 -- Copyright (C) 2008-2017 Matthew Wild |
|
80ee0d9cd56f
mod_mam: Normalize copyright headers
Kim Alvefur <zash@zash.se>
parents:
7850
diff
changeset
|
3 -- Copyright (C) 2008-2017 Waqas Hussain |
|
11272
44c9cb4094bb
mod_mam: Add support for before-id and after-id fields
Kim Alvefur <zash@zash.se>
parents:
11270
diff
changeset
|
4 -- Copyright (C) 2011-2021 Kim Alvefur |
|
7851
80ee0d9cd56f
mod_mam: Normalize copyright headers
Kim Alvefur <zash@zash.se>
parents:
7850
diff
changeset
|
5 -- |
|
80ee0d9cd56f
mod_mam: Normalize copyright headers
Kim Alvefur <zash@zash.se>
parents:
7850
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
|
80ee0d9cd56f
mod_mam: Normalize copyright headers
Kim Alvefur <zash@zash.se>
parents:
7850
diff
changeset
|
7 -- COPYING file in the source package for more information. |
|
80ee0d9cd56f
mod_mam: Normalize copyright headers
Kim Alvefur <zash@zash.se>
parents:
7850
diff
changeset
|
8 -- |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 -- XEP-0313: Message Archive Management for Prosody |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 -- |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 |
|
14039
4421dcb755b5
mod_mam: Automatically load mod_muc_mam if loaded on a MUC component
Matthew Wild <mwild1@gmail.com>
parents:
13992
diff
changeset
|
12 if module:get_host_type() == "component" and module:get_option_string("component_module") == "muc" then |
|
4421dcb755b5
mod_mam: Automatically load mod_muc_mam if loaded on a MUC component
Matthew Wild <mwild1@gmail.com>
parents:
13992
diff
changeset
|
13 module:depends("muc_mam"); |
|
4421dcb755b5
mod_mam: Automatically load mod_muc_mam if loaded on a MUC component
Matthew Wild <mwild1@gmail.com>
parents:
13992
diff
changeset
|
14 return; |
|
4421dcb755b5
mod_mam: Automatically load mod_muc_mam if loaded on a MUC component
Matthew Wild <mwild1@gmail.com>
parents:
13992
diff
changeset
|
15 end |
|
4421dcb755b5
mod_mam: Automatically load mod_muc_mam if loaded on a MUC component
Matthew Wild <mwild1@gmail.com>
parents:
13992
diff
changeset
|
16 |
|
7903
036c771b842a
mod_mam: Update namespace to XEP-0313 v0.6
Kim Alvefur <zash@zash.se>
parents:
7902
diff
changeset
|
17 local xmlns_mam = "urn:xmpp:mam:2"; |
|
11268
e3f6f0b39e7b
mod_mam: Advertise extended MAM 0.7.x behind a feature flag
Kim Alvefur <zash@zash.se>
parents:
11260
diff
changeset
|
18 local xmlns_mam_ext = "urn:xmpp:mam:2#extended"; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local xmlns_delay = "urn:xmpp:delay"; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local xmlns_forward = "urn:xmpp:forward:0"; |
|
7890
9e4de27e8e08
mod_mam: Move stanza ID namespace to a common variable
Kim Alvefur <zash@zash.se>
parents:
7882
diff
changeset
|
21 local xmlns_st_id = "urn:xmpp:sid:0"; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
23 local um = require "prosody.core.usermanager"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
24 local st = require "prosody.util.stanza"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
25 local rsm = require "prosody.util.rsm"; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 local get_prefs = module:require"mamprefs".get; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 local set_prefs = module:require"mamprefs".set; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 local prefs_to_stanza = module:require"mamprefsxml".tostanza; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 local prefs_from_stanza = module:require"mamprefsxml".fromstanza; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
30 local jid_bare = require "prosody.util.jid".bare; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
31 local jid_split = require "prosody.util.jid".split; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
32 local jid_resource = require "prosody.util.jid".resource; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
33 local jid_prepped_split = require "prosody.util.jid".prepped_split; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
34 local dataform = require "prosody.util.dataforms".new; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
35 local get_form_type = require "prosody.util.dataforms".get_type; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 local host = module.host; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
38 local rm_load_roster = require "prosody.core.rostermanager".load_roster; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 |
|
7838
e5d5e5946af5
mod_mam: Use is_stanza from util.stanza
Kim Alvefur <zash@zash.se>
parents:
7837
diff
changeset
|
40 local is_stanza = st.is_stanza; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 local tostring = tostring; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
42 local time_now = require "prosody.util.time".now; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 local m_min = math.min; |
|
13055
e732f9dfdfc8
mod_mam: port to use util.human.io.parse_duration
Jonas Schäfer <jonas@wielicki.name>
parents:
12977
diff
changeset
|
44 local timestamp, datestamp = import( "util.datetime", "datetime", "date"); |
|
13213
50324f66ca2a
plugins: Use integer config API with interval specification where sensible
Kim Alvefur <zash@zash.se>
parents:
13209
diff
changeset
|
45 local default_max_items, max_max_items = 20, module:get_option_integer("max_archive_query_results", 50, 0); |
|
7849
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
46 local strip_tags = module:get_option_set("dont_archive_namespaces", { "http://jabber.org/protocol/chatstates" }); |
|
13992
9cfc62b4625b
mod_mam: Add send_legacy_offline_messages_to_mam_clients config option
Matthew Wild <mwild1@gmail.com>
parents:
13790
diff
changeset
|
47 local send_legacy_offline_to_mam_clients = module:get_option_boolean("send_legacy_offline_messages_to_mam_clients", false); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 |
|
7850
10d91860172f
mod_mam: Change store name to "archive" but make it configurable for people who have data in "archive2"
Kim Alvefur <zash@zash.se>
parents:
7849
diff
changeset
|
49 local archive_store = module:get_option_string("archive_store", "archive"); |
|
8047
eb9784561387
mod_mam: Remove extraneous assert when opening the store
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8000
diff
changeset
|
50 local archive = module:open_store(archive_store, "archive"); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 |
|
13209
c8d949cf6b09
plugins: Switch to :get_option_period() for time range options
Kim Alvefur <zash@zash.se>
parents:
13165
diff
changeset
|
52 local cleanup_after = module:get_option_period("archive_expires_after", "1w"); |
|
13213
50324f66ca2a
plugins: Use integer config API with interval specification where sensible
Kim Alvefur <zash@zash.se>
parents:
13209
diff
changeset
|
53 local archive_item_limit = module:get_option_integer("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000, 0); |
|
10800
62794e065e33
MAM: Remove 1% of contents when reaching limits, fix #1545
Kim Alvefur <zash@zash.se>
parents:
10773
diff
changeset
|
54 local archive_truncate = math.floor(archive_item_limit * 0.99); |
|
62794e065e33
MAM: Remove 1% of contents when reaching limits, fix #1545
Kim Alvefur <zash@zash.se>
parents:
10773
diff
changeset
|
55 |
|
9553
9a5485550bfd
mod_mam: Ignore case of null storage driver
Kim Alvefur <zash@zash.se>
parents:
8905
diff
changeset
|
56 if not archive.find then |
|
9554
cba6e6168d26
mod_mam: Upgrade case of invalid archive store driver to hard error
Kim Alvefur <zash@zash.se>
parents:
9553
diff
changeset
|
57 error("mod_"..(archive._provided_by or archive.name and "storage_"..archive.name).." does not support archiving\n" |
|
cba6e6168d26
mod_mam: Upgrade case of invalid archive store driver to hard error
Kim Alvefur <zash@zash.se>
parents:
9553
diff
changeset
|
58 .."See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information"); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 end |
|
8577
75d5eee6fcdf
mod_mam: Add an option for whether to include 'total' counts by default in queries
Kim Alvefur <zash@zash.se>
parents:
8576
diff
changeset
|
60 local use_total = module:get_option_boolean("mam_include_total", true); |
|
8132
6ddddfe05a74
mod_mam: Don't ask the storage backend to count all items when expiry is disabled
Kim Alvefur <zash@zash.se>
parents:
8047
diff
changeset
|
61 |
|
12556
706375b75475
mod_mam: Silence luacheck (yay warnings in CI but not locally)
Kim Alvefur <zash@zash.se>
parents:
12555
diff
changeset
|
62 function schedule_cleanup(_username, _date) -- luacheck: ignore 212 |
|
12555
519e6403f455
mod_mam: Clarify comment (thanks chili-b)
Kim Alvefur <zash@zash.se>
parents:
12307
diff
changeset
|
63 -- Called to make a note of which users have messages on which days, which in |
|
519e6403f455
mod_mam: Clarify comment (thanks chili-b)
Kim Alvefur <zash@zash.se>
parents:
12307
diff
changeset
|
64 -- turn is used to optimize the message expiry routine. |
|
519e6403f455
mod_mam: Clarify comment (thanks chili-b)
Kim Alvefur <zash@zash.se>
parents:
12307
diff
changeset
|
65 -- |
|
519e6403f455
mod_mam: Clarify comment (thanks chili-b)
Kim Alvefur <zash@zash.se>
parents:
12307
diff
changeset
|
66 -- This noop is conditionally replaced later depending on retention settings |
|
519e6403f455
mod_mam: Clarify comment (thanks chili-b)
Kim Alvefur <zash@zash.se>
parents:
12307
diff
changeset
|
67 -- and storage backend capabilities. |
|
8230
154852646095
mod_mam: Use a FIFO queue for scheduling archive expiry
Kim Alvefur <zash@zash.se>
parents:
8207
diff
changeset
|
68 end |
|
154852646095
mod_mam: Use a FIFO queue for scheduling archive expiry
Kim Alvefur <zash@zash.se>
parents:
8207
diff
changeset
|
69 |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 -- Handle prefs. |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 module:hook("iq/self/"..xmlns_mam..":prefs", function(event) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 local origin, stanza = event.origin, event.stanza; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 local user = origin.username; |
|
8252
63e505578d4f
mod_mam: Also return the preferences on set
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8250
diff
changeset
|
74 if stanza.attr.type == "set" then |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 local new_prefs = stanza:get_child("prefs", xmlns_mam); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 local prefs = prefs_from_stanza(new_prefs); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 local ok, err = set_prefs(user, prefs); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 if not ok then |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", "Error storing preferences: "..tostring(err))); |
|
8252
63e505578d4f
mod_mam: Also return the preferences on set
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8250
diff
changeset
|
80 return true; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 end |
|
8538
3eb4cafb3b64
mod_mam: Implement option to enable MAM implicitly when client support is detected (#867)
Kim Alvefur <zash@zash.se>
parents:
8252
diff
changeset
|
83 local prefs = prefs_to_stanza(get_prefs(user, true)); |
|
8252
63e505578d4f
mod_mam: Also return the preferences on set
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8250
diff
changeset
|
84 local reply = st.reply(stanza):add_child(prefs); |
|
63e505578d4f
mod_mam: Also return the preferences on set
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8250
diff
changeset
|
85 origin.send(reply); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 return true; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 end); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 local query_form = dataform { |
|
11875
210a785dfa8a
mod_mam: Use util.dataforms timestamp validation
Kim Alvefur <zash@zash.se>
parents:
11819
diff
changeset
|
90 { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam }; |
|
210a785dfa8a
mod_mam: Use util.dataforms timestamp validation
Kim Alvefur <zash@zash.se>
parents:
11819
diff
changeset
|
91 { name = "with"; type = "jid-single" }; |
|
210a785dfa8a
mod_mam: Use util.dataforms timestamp validation
Kim Alvefur <zash@zash.se>
parents:
11819
diff
changeset
|
92 { name = "start"; type = "text-single"; datatype = "xs:dateTime" }; |
|
210a785dfa8a
mod_mam: Use util.dataforms timestamp validation
Kim Alvefur <zash@zash.se>
parents:
11819
diff
changeset
|
93 { name = "end"; type = "text-single"; datatype = "xs:dateTime" }; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 }; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 |
|
11272
44c9cb4094bb
mod_mam: Add support for before-id and after-id fields
Kim Alvefur <zash@zash.se>
parents:
11270
diff
changeset
|
96 if archive.caps and archive.caps.full_id_range then |
|
44c9cb4094bb
mod_mam: Add support for before-id and after-id fields
Kim Alvefur <zash@zash.se>
parents:
11270
diff
changeset
|
97 table.insert(query_form, { name = "before-id"; type = "text-single"; }); |
|
44c9cb4094bb
mod_mam: Add support for before-id and after-id fields
Kim Alvefur <zash@zash.se>
parents:
11270
diff
changeset
|
98 table.insert(query_form, { name = "after-id"; type = "text-single"; }); |
|
44c9cb4094bb
mod_mam: Add support for before-id and after-id fields
Kim Alvefur <zash@zash.se>
parents:
11270
diff
changeset
|
99 end |
|
44c9cb4094bb
mod_mam: Add support for before-id and after-id fields
Kim Alvefur <zash@zash.se>
parents:
11270
diff
changeset
|
100 |
|
11280
e35e98541ca0
mod_mam: Allow querying by set of IDs
Kim Alvefur <zash@zash.se>
parents:
11272
diff
changeset
|
101 if archive.caps and archive.caps.ids then |
|
e35e98541ca0
mod_mam: Allow querying by set of IDs
Kim Alvefur <zash@zash.se>
parents:
11272
diff
changeset
|
102 table.insert(query_form, { name = "ids"; type = "list-multi"; }); |
|
e35e98541ca0
mod_mam: Allow querying by set of IDs
Kim Alvefur <zash@zash.se>
parents:
11272
diff
changeset
|
103 end |
|
e35e98541ca0
mod_mam: Allow querying by set of IDs
Kim Alvefur <zash@zash.se>
parents:
11272
diff
changeset
|
104 |
|
e35e98541ca0
mod_mam: Allow querying by set of IDs
Kim Alvefur <zash@zash.se>
parents:
11272
diff
changeset
|
105 |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 -- Serve form |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 module:hook("iq-get/self/"..xmlns_mam..":query", function(event) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 local origin, stanza = event.origin, event.stanza; |
|
8538
3eb4cafb3b64
mod_mam: Implement option to enable MAM implicitly when client support is detected (#867)
Kim Alvefur <zash@zash.se>
parents:
8252
diff
changeset
|
109 get_prefs(origin.username, true); |
|
7904
c011cecad576
mod_mam: Add missing wrapping <query> element when returning the query form
Kim Alvefur <zash@zash.se>
parents:
7903
diff
changeset
|
110 origin.send(st.reply(stanza):query(xmlns_mam):add_child(query_form:form())); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 return true; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 end); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 -- Handle archive queries |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 module:hook("iq-set/self/"..xmlns_mam..":query", function(event) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 local origin, stanza = event.origin, event.stanza; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 local query = stanza.tags[1]; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 local qid = query.attr.queryid; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 |
|
10298
906ea5e1ec75
mod_mam: Add flag to session when it performs a MAM query
Matthew Wild <mwild1@gmail.com>
parents:
10028
diff
changeset
|
120 origin.mam_requested = true; |
|
906ea5e1ec75
mod_mam: Add flag to session when it performs a MAM query
Matthew Wild <mwild1@gmail.com>
parents:
10028
diff
changeset
|
121 |
|
8538
3eb4cafb3b64
mod_mam: Implement option to enable MAM implicitly when client support is detected (#867)
Kim Alvefur <zash@zash.se>
parents:
8252
diff
changeset
|
122 get_prefs(origin.username, true); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 -- Search query parameters |
|
11280
e35e98541ca0
mod_mam: Allow querying by set of IDs
Kim Alvefur <zash@zash.se>
parents:
11272
diff
changeset
|
125 local qwith, qstart, qend, qbefore, qafter, qids; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 local form = query:get_child("x", "jabber:x:data"); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 if form then |
|
10559
cfc05e46b979
mod_mam: More careful validation of MAM query form
Kim Alvefur <zash@zash.se>
parents:
10299
diff
changeset
|
128 local form_type, err = get_form_type(form); |
|
cfc05e46b979
mod_mam: More careful validation of MAM query form
Kim Alvefur <zash@zash.se>
parents:
10299
diff
changeset
|
129 if not form_type then |
|
cfc05e46b979
mod_mam: More careful validation of MAM query form
Kim Alvefur <zash@zash.se>
parents:
10299
diff
changeset
|
130 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid dataform: "..err)); |
|
cfc05e46b979
mod_mam: More careful validation of MAM query form
Kim Alvefur <zash@zash.se>
parents:
10299
diff
changeset
|
131 return true; |
|
cfc05e46b979
mod_mam: More careful validation of MAM query form
Kim Alvefur <zash@zash.se>
parents:
10299
diff
changeset
|
132 elseif form_type ~= xmlns_mam then |
|
cfc05e46b979
mod_mam: More careful validation of MAM query form
Kim Alvefur <zash@zash.se>
parents:
10299
diff
changeset
|
133 origin.send(st.error_reply(stanza, "modify", "bad-request", "Unexpected FORM_TYPE, expected '"..xmlns_mam.."'")); |
|
cfc05e46b979
mod_mam: More careful validation of MAM query form
Kim Alvefur <zash@zash.se>
parents:
10299
diff
changeset
|
134 return true; |
|
cfc05e46b979
mod_mam: More careful validation of MAM query form
Kim Alvefur <zash@zash.se>
parents:
10299
diff
changeset
|
135 end |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 form, err = query_form:data(form); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 if err then |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err)))); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 return true; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 qwith, qstart, qend = form["with"], form["start"], form["end"]; |
|
11272
44c9cb4094bb
mod_mam: Add support for before-id and after-id fields
Kim Alvefur <zash@zash.se>
parents:
11270
diff
changeset
|
142 qbefore, qafter = form["before-id"], form["after-id"]; |
|
11280
e35e98541ca0
mod_mam: Allow querying by set of IDs
Kim Alvefur <zash@zash.se>
parents:
11272
diff
changeset
|
143 qids = form["ids"]; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 qwith = qwith and jid_bare(qwith); -- dataforms does jidprep |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 -- RSM stuff |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 local qset = rsm.get(query); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 local reverse = qset and qset.before or false; |
|
12857
cc86d77481fc
mod_mam,mod_muc_mam: Minimize differences (reorder, copy some comments)
Kim Alvefur <zash@zash.se>
parents:
12307
diff
changeset
|
151 |
|
11272
44c9cb4094bb
mod_mam: Add support for before-id and after-id fields
Kim Alvefur <zash@zash.se>
parents:
11270
diff
changeset
|
152 local before, after = qset and qset.before or qbefore, qset and qset.after or qafter; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 if type(before) ~= "string" then before = nil; end |
|
11819
f590e3c51eff
mod_mam: Merge main and RSM-specific log message here too
Kim Alvefur <zash@zash.se>
parents:
11795
diff
changeset
|
154 |
|
12857
cc86d77481fc
mod_mam,mod_muc_mam: Minimize differences (reorder, copy some comments)
Kim Alvefur <zash@zash.se>
parents:
12307
diff
changeset
|
155 -- A reverse query needs to be flipped |
|
cc86d77481fc
mod_mam,mod_muc_mam: Minimize differences (reorder, copy some comments)
Kim Alvefur <zash@zash.se>
parents:
12307
diff
changeset
|
156 local flip = reverse; |
|
cc86d77481fc
mod_mam,mod_muc_mam: Minimize differences (reorder, copy some comments)
Kim Alvefur <zash@zash.se>
parents:
12307
diff
changeset
|
157 -- A flip-page query needs to be the opposite of that. |
|
cc86d77481fc
mod_mam,mod_muc_mam: Minimize differences (reorder, copy some comments)
Kim Alvefur <zash@zash.se>
parents:
12307
diff
changeset
|
158 if query:get_child("flip-page") then flip = not flip end |
|
11819
f590e3c51eff
mod_mam: Merge main and RSM-specific log message here too
Kim Alvefur <zash@zash.se>
parents:
11795
diff
changeset
|
159 |
|
f590e3c51eff
mod_mam: Merge main and RSM-specific log message here too
Kim Alvefur <zash@zash.se>
parents:
11795
diff
changeset
|
160 module:log("debug", "Archive query by %s id=%s with=%s when=%s...%s rsm=%q", |
|
f590e3c51eff
mod_mam: Merge main and RSM-specific log message here too
Kim Alvefur <zash@zash.se>
parents:
11795
diff
changeset
|
161 origin.username, |
|
f590e3c51eff
mod_mam: Merge main and RSM-specific log message here too
Kim Alvefur <zash@zash.se>
parents:
11795
diff
changeset
|
162 qid or stanza.attr.id, |
|
f590e3c51eff
mod_mam: Merge main and RSM-specific log message here too
Kim Alvefur <zash@zash.se>
parents:
11795
diff
changeset
|
163 qwith or "*", |
|
f590e3c51eff
mod_mam: Merge main and RSM-specific log message here too
Kim Alvefur <zash@zash.se>
parents:
11795
diff
changeset
|
164 qstart and timestamp(qstart) or "", |
|
f590e3c51eff
mod_mam: Merge main and RSM-specific log message here too
Kim Alvefur <zash@zash.se>
parents:
11795
diff
changeset
|
165 qend and timestamp(qend) or "", |
|
f590e3c51eff
mod_mam: Merge main and RSM-specific log message here too
Kim Alvefur <zash@zash.se>
parents:
11795
diff
changeset
|
166 qset); |
|
f590e3c51eff
mod_mam: Merge main and RSM-specific log message here too
Kim Alvefur <zash@zash.se>
parents:
11795
diff
changeset
|
167 |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
168 -- Load all the data! |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
169 local data, err = archive:find(origin.username, { |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
170 start = qstart; ["end"] = qend; -- Time range |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
171 with = qwith; |
|
8904
faca839ddbbb
mod_mam: Handle edge-case of max=0 so that complete attr is set (fixes #1128)
Kim Alvefur <zash@zash.se>
parents:
8580
diff
changeset
|
172 limit = qmax == 0 and 0 or qmax + 1; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
173 before = before; after = after; |
|
11280
e35e98541ca0
mod_mam: Allow querying by set of IDs
Kim Alvefur <zash@zash.se>
parents:
11272
diff
changeset
|
174 ids = qids; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
175 reverse = reverse; |
|
8172
66e32c34250b
mod_mam: Request a total count if no items are requested
Kim Alvefur <zash@zash.se>
parents:
8149
diff
changeset
|
176 total = use_total or qmax == 0; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
177 }); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
178 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
179 if not data then |
|
10076
ee85cea08127
mod_mam: Log query failure reason
Kim Alvefur <zash@zash.se>
parents:
10075
diff
changeset
|
180 module:log("debug", "Archive query id=%s failed: %s", qid or stanza.attr.id, err); |
|
10021
4715c5d1eb69
mod_mam: Propagate item-not-found to client (fixes #1325)
Kim Alvefur <zash@zash.se>
parents:
9894
diff
changeset
|
181 if err == "item-not-found" then |
|
4715c5d1eb69
mod_mam: Propagate item-not-found to client (fixes #1325)
Kim Alvefur <zash@zash.se>
parents:
9894
diff
changeset
|
182 origin.send(st.error_reply(stanza, "modify", "item-not-found")); |
|
4715c5d1eb69
mod_mam: Propagate item-not-found to client (fixes #1325)
Kim Alvefur <zash@zash.se>
parents:
9894
diff
changeset
|
183 else |
|
4715c5d1eb69
mod_mam: Propagate item-not-found to client (fixes #1325)
Kim Alvefur <zash@zash.se>
parents:
9894
diff
changeset
|
184 origin.send(st.error_reply(stanza, "cancel", "internal-server-error")); |
|
4715c5d1eb69
mod_mam: Propagate item-not-found to client (fixes #1325)
Kim Alvefur <zash@zash.se>
parents:
9894
diff
changeset
|
185 end |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
186 return true; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
187 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
188 local total = tonumber(err); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
189 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
190 local msg_reply_attr = { to = stanza.attr.from, from = stanza.attr.to }; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
191 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
192 local results = {}; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
193 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
194 -- Wrap it in stuff and deliver |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
195 local first, last; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
196 local count = 0; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
197 local complete = "true"; |
|
14007
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
198 local oldest, newest; |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
199 for id, item, when in data do |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
200 count = count + 1; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
201 if count > qmax then |
|
8905
65d1a80d3565
mod_mam: Add coment on how 'complete' works
Kim Alvefur <zash@zash.se>
parents:
8904
diff
changeset
|
202 -- We requested qmax+1 items. If that many items are retrieved then |
|
65d1a80d3565
mod_mam: Add coment on how 'complete' works
Kim Alvefur <zash@zash.se>
parents:
8904
diff
changeset
|
203 -- there are more results to page through, so: |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
204 complete = nil; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
205 break; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
206 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
207 local fwd_st = st.message(msg_reply_attr) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
208 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
209 :tag("forwarded", { xmlns = xmlns_forward }) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
210 :tag("delay", { xmlns = xmlns_delay, stamp = timestamp(when) }):up(); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
211 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
212 if not is_stanza(item) then |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
213 item = st.deserialize(item); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
214 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
215 item.attr.xmlns = "jabber:client"; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
216 fwd_st:add_child(item); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
217 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
218 if not first then first = id; end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
219 last = id; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
220 |
|
14007
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
221 if not newest or when > newest then |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
222 newest = when; |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
223 end |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
224 if not oldest or when < oldest then |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
225 oldest = when; |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
226 end |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
227 |
|
11269
342ac5d806fb
mod_mam: Add support for page flipping
Kim Alvefur <zash@zash.se>
parents:
11268
diff
changeset
|
228 if flip then |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
229 results[count] = fwd_st; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
230 else |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
231 origin.send(fwd_st); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
232 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
233 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
234 |
|
11269
342ac5d806fb
mod_mam: Add support for page flipping
Kim Alvefur <zash@zash.se>
parents:
11268
diff
changeset
|
235 if flip then |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
236 for i = #results, 1, -1 do |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
237 origin.send(results[i]); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
238 end |
|
11269
342ac5d806fb
mod_mam: Add support for page flipping
Kim Alvefur <zash@zash.se>
parents:
11268
diff
changeset
|
239 end |
|
342ac5d806fb
mod_mam: Add support for page flipping
Kim Alvefur <zash@zash.se>
parents:
11268
diff
changeset
|
240 if reverse then |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
241 first, last = last, first; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
242 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
243 |
|
7839
f3e1925f29c2
mod_mam: Update to XEP-0313 v0.5.1
Kim Alvefur <zash@zash.se>
parents:
7838
diff
changeset
|
244 origin.send(st.reply(stanza) |
|
11337
f89c8e6beaa6
mod_mam: Remove obsolete 'queryid' attribute from iq-result (thanks paul)
Kim Alvefur <zash@zash.se>
parents:
11281
diff
changeset
|
245 :tag("fin", { xmlns = xmlns_mam, complete = complete }) |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
246 :add_child(rsm.generate { |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
247 first = first, last = last, count = total })); |
|
10078
44371850c6b0
mod_mam: Move final log message to end of query procedure
Kim Alvefur <zash@zash.se>
parents:
10077
diff
changeset
|
248 |
|
14007
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
249 module:fire_event("archive-query-result", { |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
250 origin = origin; |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
251 stanza = stanza; |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
252 first_time = oldest; |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
253 last_time = newest; |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
254 first_id = reverse and last or first; |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
255 last_id = reverse and first or last; |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
256 }); |
|
8fb7408ded73
mod_mam: Fire event when a query has been processed
Matthew Wild <mwild1@gmail.com>
parents:
14005
diff
changeset
|
257 |
|
10078
44371850c6b0
mod_mam: Move final log message to end of query procedure
Kim Alvefur <zash@zash.se>
parents:
10077
diff
changeset
|
258 -- That's all folks! |
|
10079
a36c731ed540
mod_mam: Report correct count of results for forward queries
Kim Alvefur <zash@zash.se>
parents:
10078
diff
changeset
|
259 module:log("debug", "Archive query id=%s completed, %d items returned", qid or stanza.attr.id, complete and count or count - 1); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
260 return true; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
261 end); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
262 |
|
11270
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
263 module:hook("iq-get/self/"..xmlns_mam..":metadata", function (event) |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
264 local origin, stanza = event.origin, event.stanza; |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
265 |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
266 local reply = st.reply(stanza):tag("metadata", { xmlns = xmlns_mam }); |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
267 |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
268 do |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
269 local first = archive:find(origin.username, { limit = 1 }); |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
270 if not first then |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
271 origin.send(st.error_reply(stanza, "cancel", "internal-server-error")); |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
272 return true; |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
273 end |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
274 |
|
13357
f424c9f1460b
mod_mam: Use for loop in metadata query
Kim Alvefur <zash@zash.se>
parents:
13230
diff
changeset
|
275 for id, _, when in first do |
|
11270
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
276 reply:tag("start", { id = id, timestamp = timestamp(when) }):up(); |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
277 end |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
278 end |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
279 |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
280 do |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
281 local last = archive:find(origin.username, { limit = 1, reverse = true }); |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
282 if not last then |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
283 origin.send(st.error_reply(stanza, "cancel", "internal-server-error")); |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
284 return true; |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
285 end |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
286 |
|
13357
f424c9f1460b
mod_mam: Use for loop in metadata query
Kim Alvefur <zash@zash.se>
parents:
13230
diff
changeset
|
287 for id, _, when in last do |
|
11270
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
288 reply:tag("end", { id = id, timestamp = timestamp(when) }):up(); |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
289 end |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
290 end |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
291 |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
292 origin.send(reply); |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
293 return true; |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
294 end); |
|
eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
Kim Alvefur <zash@zash.se>
parents:
11269
diff
changeset
|
295 |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
296 local function has_in_roster(user, who) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
297 local roster = rm_load_roster(user, host); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
298 module:log("debug", "%s has %s in roster? %s", user, who, roster[who] and "yes" or "no"); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
299 return roster[who]; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
300 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
301 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
302 local function shall_store(user, who) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
303 -- TODO Cache this? |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
304 if not um.user_exists(user, host) then |
|
9879
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
305 module:log("debug", "%s@%s does not exist", user, host) |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
306 return false; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
307 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
308 local prefs = get_prefs(user); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
309 local rule = prefs[who]; |
|
10111
0f335815244f
plugins: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
10079
diff
changeset
|
310 module:log("debug", "%s's rule for %s is %s", user, who, rule); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
311 if rule ~= nil then |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
312 return rule; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
313 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
314 -- Below could be done by a metatable |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
315 local default = prefs[false]; |
|
10111
0f335815244f
plugins: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
10079
diff
changeset
|
316 module:log("debug", "%s's default rule is %s", user, default); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
317 if default == "roster" then |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
318 return has_in_roster(user, who); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
319 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
320 return default; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
321 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
322 |
|
8207
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
323 local function strip_stanza_id(stanza, user) |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
324 if stanza:get_child("stanza-id", xmlns_st_id) then |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
325 stanza = st.clone(stanza); |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
326 stanza:maptags(function (tag) |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
327 if tag.name == "stanza-id" and tag.attr.xmlns == xmlns_st_id then |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
328 local by_user, by_host, res = jid_prepped_split(tag.attr.by); |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
329 if not res and by_host == host and by_user == user then |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
330 return nil; |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
331 end |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
332 end |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
333 return tag; |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
334 end); |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
335 end |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
336 return stanza; |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
337 end |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
338 |
|
12306
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
339 local function should_store(stanza) --> boolean, reason: string |
|
10736
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
340 local st_type = stanza.attr.type or "normal"; |
|
10751
4db4bd8a7822
mod_mam: Don't store any groupchat messages
Kim Alvefur <zash@zash.se>
parents:
10746
diff
changeset
|
341 -- FIXME pass direction of stanza and use that along with bare/full JID addressing |
|
4db4bd8a7822
mod_mam: Don't store any groupchat messages
Kim Alvefur <zash@zash.se>
parents:
10746
diff
changeset
|
342 -- for more accurate MUC / type=groupchat check |
|
10734
136c41a3d03c
mod_mam: Factor out "should we store this" into a function
Kim Alvefur <zash@zash.se>
parents:
10683
diff
changeset
|
343 |
|
10736
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
344 if st_type == "headline" then |
|
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
345 -- Headline messages are ephemeral by definition |
|
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
346 return false, "headline"; |
|
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
347 end |
|
12306
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
348 if st_type == "error" then |
|
12030
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
349 -- Errors not sent sent from a local client |
|
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
350 -- Why would a client send an error anyway? |
|
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
351 if jid_resource(stanza.attr.to) then |
|
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
352 -- Store delivery failure notifications so you know if your own messages |
|
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
353 -- were not delivered. |
|
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
354 return true, "bounce"; |
|
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
355 else |
|
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
356 -- Skip errors for messages that come from your account, such as PEP |
|
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
357 -- notifications. |
|
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
358 return false, "bounce"; |
|
9f8206e99b89
mod_mam: Avoid storing bounces for messages from the bare account (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11988
diff
changeset
|
359 end |
|
10745
79b29f35fac1
mod_mam: Save delivery failures (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
10744
diff
changeset
|
360 end |
|
10751
4db4bd8a7822
mod_mam: Don't store any groupchat messages
Kim Alvefur <zash@zash.se>
parents:
10746
diff
changeset
|
361 if st_type == "groupchat" then |
|
10736
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
362 -- MUC messages always go to the full JID, usually archived by the MUC |
|
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
363 return false, "groupchat"; |
|
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
364 end |
|
10743
3967cf10de1b
mod_mam: Respect no-store hint (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
10742
diff
changeset
|
365 if stanza:get_child("no-store", "urn:xmpp:hints") |
|
3967cf10de1b
mod_mam: Respect no-store hint (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
10742
diff
changeset
|
366 or stanza:get_child("no-permanent-store", "urn:xmpp:hints") then |
|
10737
b2ede421adeb
mod_mam: Rework hints handling
Kim Alvefur <zash@zash.se>
parents:
10736
diff
changeset
|
367 return false, "hint"; |
|
b2ede421adeb
mod_mam: Rework hints handling
Kim Alvefur <zash@zash.se>
parents:
10736
diff
changeset
|
368 end |
|
b2ede421adeb
mod_mam: Rework hints handling
Kim Alvefur <zash@zash.se>
parents:
10736
diff
changeset
|
369 if stanza:get_child("store", "urn:xmpp:hints") then |
|
b2ede421adeb
mod_mam: Rework hints handling
Kim Alvefur <zash@zash.se>
parents:
10736
diff
changeset
|
370 return true, "hint"; |
|
b2ede421adeb
mod_mam: Rework hints handling
Kim Alvefur <zash@zash.se>
parents:
10736
diff
changeset
|
371 end |
|
10736
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
372 if stanza:get_child("body") then |
|
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
373 return true, "body"; |
|
c5a3576a5335
mod_mam: Invert check for type
Kim Alvefur <zash@zash.se>
parents:
10735
diff
changeset
|
374 end |
|
10738
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
375 if stanza:get_child("subject") then |
| 10742 | 376 -- XXX Who would send a message with a subject but without a body? |
|
10738
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
377 return true, "subject"; |
|
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
378 end |
|
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
379 if stanza:get_child("encryption", "urn:xmpp:eme:0") then |
|
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
380 -- Since we can't know what an encrypted message contains, we assume it's important |
|
10746
2e31d67b9a29
mod_mam: Make note of Experimental (or Deferred) XEPs
Kim Alvefur <zash@zash.se>
parents:
10745
diff
changeset
|
381 -- XXX Experimental XEP |
|
10738
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
382 return true, "encrypted"; |
|
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
383 end |
|
10739
50f0a4d83731
mod_mam: Store XEP-0184 receipts and requests
Kim Alvefur <zash@zash.se>
parents:
10738
diff
changeset
|
384 if stanza:get_child(nil, "urn:xmpp:receipts") then |
|
50f0a4d83731
mod_mam: Store XEP-0184 receipts and requests
Kim Alvefur <zash@zash.se>
parents:
10738
diff
changeset
|
385 -- If it's important enough to ask for a receipt then it's important enough to archive |
|
50f0a4d83731
mod_mam: Store XEP-0184 receipts and requests
Kim Alvefur <zash@zash.se>
parents:
10738
diff
changeset
|
386 -- and the same applies to the receipt |
|
50f0a4d83731
mod_mam: Store XEP-0184 receipts and requests
Kim Alvefur <zash@zash.se>
parents:
10738
diff
changeset
|
387 return true, "receipt"; |
|
50f0a4d83731
mod_mam: Store XEP-0184 receipts and requests
Kim Alvefur <zash@zash.se>
parents:
10738
diff
changeset
|
388 end |
|
10744
16002abe61b1
mod_mam: Keep chat markers (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
10743
diff
changeset
|
389 if stanza:get_child(nil, "urn:xmpp:chat-markers:0") then |
|
16002abe61b1
mod_mam: Keep chat markers (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
10743
diff
changeset
|
390 return true, "marker"; |
|
16002abe61b1
mod_mam: Keep chat markers (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
10743
diff
changeset
|
391 end |
|
10738
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
392 if stanza:get_child("x", "jabber:x:conference") |
|
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
393 or stanza:find("{http://jabber.org/protocol/muc#user}x/invite") then |
|
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
394 return true, "invite"; |
|
19ffb2ebf114
mod_mam: Add more positive hints for storage
Kim Alvefur <zash@zash.se>
parents:
10737
diff
changeset
|
395 end |
|
12234
1c47162dd965
plugins: Update for namespace bump in XEP-0353 v0.4.0
Kim Alvefur <zash@zash.se>
parents:
12030
diff
changeset
|
396 if stanza:get_child(nil, "urn:xmpp:jingle-message:0") or stanza:get_child(nil, "urn:xmpp:jingle-message:1") then |
|
11260
08b397c21805
mod_csi_simple,mod_carbons,mod_mam: Update comment about XEP-0353
Kim Alvefur <zash@zash.se>
parents:
10821
diff
changeset
|
397 -- XXX Experimental XEP |
|
10821
30fc1ed5647a
mod_mam: Archive XEP-0353: Jingle Message Initiation
Kim Alvefur <zash@zash.se>
parents:
10800
diff
changeset
|
398 return true, "jingle call"; |
|
30fc1ed5647a
mod_mam: Archive XEP-0353: Jingle Message Initiation
Kim Alvefur <zash@zash.se>
parents:
10800
diff
changeset
|
399 end |
|
10734
136c41a3d03c
mod_mam: Factor out "should we store this" into a function
Kim Alvefur <zash@zash.se>
parents:
10683
diff
changeset
|
400 |
|
10741
27f1fcd85ccd
mod_mam: Prefer not archiving if no interesting payloads are found
Kim Alvefur <zash@zash.se>
parents:
10740
diff
changeset
|
401 -- The IM-NG thing to do here would be to return `not st_to_full` |
|
27f1fcd85ccd
mod_mam: Prefer not archiving if no interesting payloads are found
Kim Alvefur <zash@zash.se>
parents:
10740
diff
changeset
|
402 -- One day ... |
|
27f1fcd85ccd
mod_mam: Prefer not archiving if no interesting payloads are found
Kim Alvefur <zash@zash.se>
parents:
10740
diff
changeset
|
403 return false, "default"; |
|
10734
136c41a3d03c
mod_mam: Factor out "should we store this" into a function
Kim Alvefur <zash@zash.se>
parents:
10683
diff
changeset
|
404 end |
|
136c41a3d03c
mod_mam: Factor out "should we store this" into a function
Kim Alvefur <zash@zash.se>
parents:
10683
diff
changeset
|
405 |
|
12306
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
406 module:hook("archive-should-store", function (event) |
|
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
407 local should, why = should_store(event.stanza); |
|
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
408 event.reason = why; |
|
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
409 return should; |
|
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
410 end, -1) |
|
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
411 |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
412 -- Handle messages |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
413 local function message_handler(event, c2s) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
414 local origin, stanza = event.origin, event.stanza; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
415 local log = c2s and origin.log or module._log; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
416 local orig_from = stanza.attr.from; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
417 local orig_to = stanza.attr.to or orig_from; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
418 -- Stanza without 'to' are treated as if it was to their own bare jid |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
419 |
|
11727
f3aee8a825cc
Fix various spelling errors (thanks codespell)
Kim Alvefur <zash@zash.se>
parents:
11337
diff
changeset
|
420 -- Whose storage do we put it in? |
|
7844
316f5166eedb
mod_mam: Find out which party is the user and which is the 'with' earlier
Kim Alvefur <zash@zash.se>
parents:
7843
diff
changeset
|
421 local store_user = c2s and origin.username or jid_split(orig_to); |
|
316f5166eedb
mod_mam: Find out which party is the user and which is the 'with' earlier
Kim Alvefur <zash@zash.se>
parents:
7843
diff
changeset
|
422 -- And who are they chatting with? |
|
316f5166eedb
mod_mam: Find out which party is the user and which is the 'with' earlier
Kim Alvefur <zash@zash.se>
parents:
7843
diff
changeset
|
423 local with = jid_bare(c2s and orig_to or orig_from); |
|
316f5166eedb
mod_mam: Find out which party is the user and which is the 'with' earlier
Kim Alvefur <zash@zash.se>
parents:
7843
diff
changeset
|
424 |
|
7845
eeb22f912577
mod_mam: Filter out spoofed XEP-0359 tags
Kim Alvefur <zash@zash.se>
parents:
7844
diff
changeset
|
425 -- Filter out <stanza-id> that claim to be from us |
|
8207
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
426 event.stanza = strip_stanza_id(stanza, store_user); |
|
7845
eeb22f912577
mod_mam: Filter out spoofed XEP-0359 tags
Kim Alvefur <zash@zash.se>
parents:
7844
diff
changeset
|
427 |
|
12306
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
428 local event_payload = { stanza = stanza; session = origin }; |
|
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
429 local should = module:fire_event("archive-should-store", event_payload); |
|
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
430 local why = event_payload.reason; |
|
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
431 |
|
10734
136c41a3d03c
mod_mam: Factor out "should we store this" into a function
Kim Alvefur <zash@zash.se>
parents:
10683
diff
changeset
|
432 if not should then |
|
12306
81fc7fc77e68
mod_mam: Allow plugging into archive decision
Kim Alvefur <zash@zash.se>
parents:
12234
diff
changeset
|
433 log("debug", "Not archiving stanza: %s (%s)", stanza:top_tag(), event_payload.reason); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
434 return; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
435 end |
|
7842
9332b43931f5
mod_mam: Add some comments explaining archive expiry
Kim Alvefur <zash@zash.se>
parents:
7841
diff
changeset
|
436 |
|
8193
bb0118e46c45
mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
Kim Alvefur <zash@zash.se>
parents:
8172
diff
changeset
|
437 local clone_for_storage; |
|
7849
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
438 if not strip_tags:empty() then |
|
8193
bb0118e46c45
mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
Kim Alvefur <zash@zash.se>
parents:
8172
diff
changeset
|
439 clone_for_storage = st.clone(stanza); |
|
bb0118e46c45
mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
Kim Alvefur <zash@zash.se>
parents:
8172
diff
changeset
|
440 clone_for_storage:maptags(function (tag) |
|
7849
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
441 if strip_tags:contains(tag.attr.xmlns) then |
|
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
442 return nil; |
|
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
443 else |
|
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
444 return tag; |
|
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
445 end |
|
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
446 end); |
|
8193
bb0118e46c45
mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
Kim Alvefur <zash@zash.se>
parents:
8172
diff
changeset
|
447 if #clone_for_storage.tags == 0 then |
|
8250
9ea5ea53744b
mod_mam: Log a message when not archiving because it only had ignored tags
Kim Alvefur <zash@zash.se>
parents:
8231
diff
changeset
|
448 log("debug", "Not archiving stanza: %s (empty when stripped)", stanza:top_tag()); |
|
7849
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
449 return; |
|
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
450 end |
|
8193
bb0118e46c45
mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
Kim Alvefur <zash@zash.se>
parents:
8172
diff
changeset
|
451 else |
|
bb0118e46c45
mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
Kim Alvefur <zash@zash.se>
parents:
8172
diff
changeset
|
452 clone_for_storage = stanza; |
|
7849
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
453 end |
|
93a068ef4b2c
mod_mam: Allow a set of namespaces to be stripped from stored stanzas, default to chat states (fixes #763)
Kim Alvefur <zash@zash.se>
parents:
7848
diff
changeset
|
454 |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
455 -- Check with the users preferences |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
456 if shall_store(store_user, with) then |
|
10735
f2838ffcc499
mod_mam: Log 'why' a stanza is archived
Kim Alvefur <zash@zash.se>
parents:
10734
diff
changeset
|
457 log("debug", "Archiving stanza: %s (%s)", stanza:top_tag(), why); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
458 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
459 -- And stash it |
|
9886
710a116341cd
mod_mam: Trim archive when quota has been exceeded
Kim Alvefur <zash@zash.se>
parents:
9882
diff
changeset
|
460 local time = time_now(); |
|
710a116341cd
mod_mam: Trim archive when quota has been exceeded
Kim Alvefur <zash@zash.se>
parents:
9882
diff
changeset
|
461 local ok, err = archive:append(store_user, nil, clone_for_storage, time, with); |
|
710a116341cd
mod_mam: Trim archive when quota has been exceeded
Kim Alvefur <zash@zash.se>
parents:
9882
diff
changeset
|
462 if not ok and err == "quota-limit" then |
|
13230
26c30844cac6
plugins: Handle how get_option_period returns "never"
Kim Alvefur <zash@zash.se>
parents:
13213
diff
changeset
|
463 if cleanup_after ~= math.huge then |
|
9894
8747ccf0008c
mod_mam: On quota hit, separately delete by time and by item count
Kim Alvefur <zash@zash.se>
parents:
9886
diff
changeset
|
464 module:log("debug", "User '%s' over quota, cleaning archive", store_user); |
|
8747ccf0008c
mod_mam: On quota hit, separately delete by time and by item count
Kim Alvefur <zash@zash.se>
parents:
9886
diff
changeset
|
465 local cleaned = archive:delete(store_user, { |
|
8747ccf0008c
mod_mam: On quota hit, separately delete by time and by item count
Kim Alvefur <zash@zash.se>
parents:
9886
diff
changeset
|
466 ["end"] = (os.time() - cleanup_after); |
|
8747ccf0008c
mod_mam: On quota hit, separately delete by time and by item count
Kim Alvefur <zash@zash.se>
parents:
9886
diff
changeset
|
467 }); |
|
8747ccf0008c
mod_mam: On quota hit, separately delete by time and by item count
Kim Alvefur <zash@zash.se>
parents:
9886
diff
changeset
|
468 if cleaned then |
|
8747ccf0008c
mod_mam: On quota hit, separately delete by time and by item count
Kim Alvefur <zash@zash.se>
parents:
9886
diff
changeset
|
469 ok, err = archive:append(store_user, nil, clone_for_storage, time, with); |
|
8747ccf0008c
mod_mam: On quota hit, separately delete by time and by item count
Kim Alvefur <zash@zash.se>
parents:
9886
diff
changeset
|
470 end |
|
8747ccf0008c
mod_mam: On quota hit, separately delete by time and by item count
Kim Alvefur <zash@zash.se>
parents:
9886
diff
changeset
|
471 end |
|
8747ccf0008c
mod_mam: On quota hit, separately delete by time and by item count
Kim Alvefur <zash@zash.se>
parents:
9886
diff
changeset
|
472 if not ok and (archive.caps and archive.caps.truncate) then |
|
8747ccf0008c
mod_mam: On quota hit, separately delete by time and by item count
Kim Alvefur <zash@zash.se>
parents:
9886
diff
changeset
|
473 module:log("debug", "User '%s' over quota, truncating archive", store_user); |
|
9886
710a116341cd
mod_mam: Trim archive when quota has been exceeded
Kim Alvefur <zash@zash.se>
parents:
9882
diff
changeset
|
474 local truncated = archive:delete(store_user, { |
|
10800
62794e065e33
MAM: Remove 1% of contents when reaching limits, fix #1545
Kim Alvefur <zash@zash.se>
parents:
10773
diff
changeset
|
475 truncate = archive_truncate; |
|
9886
710a116341cd
mod_mam: Trim archive when quota has been exceeded
Kim Alvefur <zash@zash.se>
parents:
9882
diff
changeset
|
476 }); |
|
710a116341cd
mod_mam: Trim archive when quota has been exceeded
Kim Alvefur <zash@zash.se>
parents:
9882
diff
changeset
|
477 if truncated then |
|
710a116341cd
mod_mam: Trim archive when quota has been exceeded
Kim Alvefur <zash@zash.se>
parents:
9882
diff
changeset
|
478 ok, err = archive:append(store_user, nil, clone_for_storage, time, with); |
|
710a116341cd
mod_mam: Trim archive when quota has been exceeded
Kim Alvefur <zash@zash.se>
parents:
9882
diff
changeset
|
479 end |
|
710a116341cd
mod_mam: Trim archive when quota has been exceeded
Kim Alvefur <zash@zash.se>
parents:
9882
diff
changeset
|
480 end |
|
710a116341cd
mod_mam: Trim archive when quota has been exceeded
Kim Alvefur <zash@zash.se>
parents:
9882
diff
changeset
|
481 end |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
482 if ok then |
|
8193
bb0118e46c45
mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
Kim Alvefur <zash@zash.se>
parents:
8172
diff
changeset
|
483 local clone_for_other_handlers = st.clone(stanza); |
|
7908
dbdaa8487ecd
mod_mam: Fix to treat first return value from archive:append as assigned ID
Kim Alvefur <zash@zash.se>
parents:
7906
diff
changeset
|
484 local id = ok; |
|
8193
bb0118e46c45
mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
Kim Alvefur <zash@zash.se>
parents:
8172
diff
changeset
|
485 clone_for_other_handlers:tag("stanza-id", { xmlns = xmlns_st_id, by = store_user.."@"..host, id = id }):up(); |
|
14005
b6d857435de1
mod_mam: Add archive-id to stanza metadata when archiving
Matthew Wild <mwild1@gmail.com>
parents:
14003
diff
changeset
|
486 clone_for_other_handlers:set_meta("archive-id", id); |
|
8193
bb0118e46c45
mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
Kim Alvefur <zash@zash.se>
parents:
8172
diff
changeset
|
487 event.stanza = clone_for_other_handlers; |
|
8230
154852646095
mod_mam: Use a FIFO queue for scheduling archive expiry
Kim Alvefur <zash@zash.se>
parents:
8207
diff
changeset
|
488 schedule_cleanup(store_user); |
|
8193
bb0118e46c45
mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
Kim Alvefur <zash@zash.se>
parents:
8172
diff
changeset
|
489 module:fire_event("archive-message-added", { origin = origin, stanza = clone_for_storage, for_user = store_user, id = id }); |
|
10523
86422db90e02
mod_mam: Log error when unable to store stanza (fix #1478)
Kim Alvefur <zash@zash.se>
parents:
10298
diff
changeset
|
490 else |
|
86422db90e02
mod_mam: Log error when unable to store stanza (fix #1478)
Kim Alvefur <zash@zash.se>
parents:
10298
diff
changeset
|
491 log("error", "Could not archive stanza: %s", err); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
492 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
493 else |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
494 log("debug", "Not archiving stanza: %s (prefs)", stanza:top_tag()); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
495 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
496 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
497 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
498 local function c2s_message_handler(event) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
499 return message_handler(event, true); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
500 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
501 |
|
8207
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
502 -- Filter out <stanza-id> before the message leaves the server to prevent privacy leak. |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
503 local function strip_stanza_id_after_other_events(event) |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
504 event.stanza = strip_stanza_id(event.stanza, event.origin.username); |
|
7902
92b70a921acb
mod_mam: Strip stanza-id tags after carbons
Kim Alvefur <zash@zash.se>
parents:
7901
diff
changeset
|
505 end |
|
92b70a921acb
mod_mam: Strip stanza-id tags after carbons
Kim Alvefur <zash@zash.se>
parents:
7901
diff
changeset
|
506 |
|
8207
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
507 module:hook("pre-message/bare", strip_stanza_id_after_other_events, -1); |
|
8ea0484871e8
mod_mam: Factor out <stanza-id> stripping so it can be reused in two places
Kim Alvefur <zash@zash.se>
parents:
8206
diff
changeset
|
508 module:hook("pre-message/full", strip_stanza_id_after_other_events, -1); |
|
7902
92b70a921acb
mod_mam: Strip stanza-id tags after carbons
Kim Alvefur <zash@zash.se>
parents:
7901
diff
changeset
|
509 |
|
11758
c35b81575d5d
mod_mam: Explain behavior with absent mod_offline in a comment
Kim Alvefur <zash@zash.se>
parents:
11757
diff
changeset
|
510 -- Catch messages not stored by mod_offline and mark them as stored if they |
|
c35b81575d5d
mod_mam: Explain behavior with absent mod_offline in a comment
Kim Alvefur <zash@zash.se>
parents:
11757
diff
changeset
|
511 -- have been archived. This would generally only happen if mod_offline is |
|
c35b81575d5d
mod_mam: Explain behavior with absent mod_offline in a comment
Kim Alvefur <zash@zash.se>
parents:
11757
diff
changeset
|
512 -- disabled. Otherwise the message would generate a delivery failure report, |
|
c35b81575d5d
mod_mam: Explain behavior with absent mod_offline in a comment
Kim Alvefur <zash@zash.se>
parents:
11757
diff
changeset
|
513 -- which would not be accurate because it has been archived. |
|
11757
8141645e3865
mod_mam: "Handle" messages that have been archived in the absense of mod_offline
Kim Alvefur <zash@zash.se>
parents:
11727
diff
changeset
|
514 module:hook("message/offline/handle", function(event) |
|
8141645e3865
mod_mam: "Handle" messages that have been archived in the absense of mod_offline
Kim Alvefur <zash@zash.se>
parents:
11727
diff
changeset
|
515 local stanza = event.stanza; |
|
11759
9925be5d3b8b
mod_mam: Only check for locally generated stanza-ids
Kim Alvefur <zash@zash.se>
parents:
11758
diff
changeset
|
516 local user = event.username .. "@" .. host; |
|
11795
41af102c7190
mod_mam: Reduce line count using new util.stanza attr method
Kim Alvefur <zash@zash.se>
parents:
11760
diff
changeset
|
517 if stanza:get_child_with_attr("stanza-id", xmlns_st_id, "by", user) then |
|
41af102c7190
mod_mam: Reduce line count using new util.stanza attr method
Kim Alvefur <zash@zash.se>
parents:
11760
diff
changeset
|
518 return true; |
|
11757
8141645e3865
mod_mam: "Handle" messages that have been archived in the absense of mod_offline
Kim Alvefur <zash@zash.se>
parents:
11727
diff
changeset
|
519 end |
|
8141645e3865
mod_mam: "Handle" messages that have been archived in the absense of mod_offline
Kim Alvefur <zash@zash.se>
parents:
11727
diff
changeset
|
520 end, -2); |
|
8141645e3865
mod_mam: "Handle" messages that have been archived in the absense of mod_offline
Kim Alvefur <zash@zash.se>
parents:
11727
diff
changeset
|
521 |
|
13992
9cfc62b4625b
mod_mam: Add send_legacy_offline_messages_to_mam_clients config option
Matthew Wild <mwild1@gmail.com>
parents:
13790
diff
changeset
|
522 if not send_legacy_offline_to_mam_clients then |
|
9cfc62b4625b
mod_mam: Add send_legacy_offline_messages_to_mam_clients config option
Matthew Wild <mwild1@gmail.com>
parents:
13790
diff
changeset
|
523 -- Don't broadcast offline messages to clients that have queried the archive. |
|
9cfc62b4625b
mod_mam: Add send_legacy_offline_messages_to_mam_clients config option
Matthew Wild <mwild1@gmail.com>
parents:
13790
diff
changeset
|
524 module:hook("message/offline/broadcast", function (event) |
|
9cfc62b4625b
mod_mam: Add send_legacy_offline_messages_to_mam_clients config option
Matthew Wild <mwild1@gmail.com>
parents:
13790
diff
changeset
|
525 if event.origin.mam_requested then |
|
9cfc62b4625b
mod_mam: Add send_legacy_offline_messages_to_mam_clients config option
Matthew Wild <mwild1@gmail.com>
parents:
13790
diff
changeset
|
526 return true; |
|
9cfc62b4625b
mod_mam: Add send_legacy_offline_messages_to_mam_clients config option
Matthew Wild <mwild1@gmail.com>
parents:
13790
diff
changeset
|
527 end |
|
9cfc62b4625b
mod_mam: Add send_legacy_offline_messages_to_mam_clients config option
Matthew Wild <mwild1@gmail.com>
parents:
13790
diff
changeset
|
528 end); |
|
9cfc62b4625b
mod_mam: Add send_legacy_offline_messages_to_mam_clients config option
Matthew Wild <mwild1@gmail.com>
parents:
13790
diff
changeset
|
529 end |
|
11760
d66738eeb875
mod_mam: Suppress offline message broadcast for MAM clients
Kim Alvefur <zash@zash.se>
parents:
11759
diff
changeset
|
530 |
|
13230
26c30844cac6
plugins: Handle how get_option_period returns "never"
Kim Alvefur <zash@zash.se>
parents:
13213
diff
changeset
|
531 if cleanup_after ~= math.huge then |
|
9879
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
532 local cleanup_storage = module:open_store("archive_cleanup"); |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
533 local cleanup_map = module:open_store("archive_cleanup", "map"); |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
534 |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
535 module:log("debug", "archive_expires_after = %d -- in seconds", cleanup_after); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
536 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
537 if not archive.delete then |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
538 module:log("error", "archive_expires_after set but mod_%s does not support deleting", archive._provided_by); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
539 return false; |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
540 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
541 |
|
9879
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
542 -- For each day, store a set of users that have new messages. To expire |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
543 -- messages, we collect the union of sets of users from dates that fall |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
544 -- outside the cleanup range. |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
545 |
|
11968
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
546 if not (archive.caps and archive.caps.wildcard_delete) then |
|
13213
50324f66ca2a
plugins: Use integer config API with interval specification where sensible
Kim Alvefur <zash@zash.se>
parents:
13209
diff
changeset
|
547 local last_date = require "prosody.util.cache".new(module:get_option_integer("archive_cleanup_date_cache_size", 1000, 1)); |
|
11968
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
548 function schedule_cleanup(username, date) |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
549 date = date or datestamp(); |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
550 if last_date:get(username) == date then return end |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
551 local ok = cleanup_map:set(date, username, true); |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
552 if ok then |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
553 last_date:set(username, date); |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
554 end |
|
10028
79ba2d709e72
mod_mam: Cache last date that archive owner has messages to reduce writes (fixes #1368)
Kim Alvefur <zash@zash.se>
parents:
9879
diff
changeset
|
555 end |
|
9879
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
556 end |
|
11968
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
557 |
|
9757
03ed7f10d8da
mod_mam: Measure how long it takes to run the message expiry job job
Kim Alvefur <zash@zash.se>
parents:
9752
diff
changeset
|
558 local cleanup_time = module:measure("cleanup", "times"); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
559 |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12860
diff
changeset
|
560 local async = require "prosody.util.async"; |
|
11988
18c0ca5fcbb8
mod_mam: Switch to new cron API
Kim Alvefur <zash@zash.se>
parents:
11968
diff
changeset
|
561 module:daily("Remove expired messages", function () |
|
9757
03ed7f10d8da
mod_mam: Measure how long it takes to run the message expiry job job
Kim Alvefur <zash@zash.se>
parents:
9752
diff
changeset
|
562 local cleanup_done = cleanup_time(); |
|
11968
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
563 |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
564 if archive.caps and archive.caps.wildcard_delete then |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
565 local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after }) |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
566 if ok then |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
567 local sum = tonumber(ok); |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
568 if sum then |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
569 module:log("info", "Deleted %d expired messages", sum); |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
570 else |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
571 -- driver did not tell |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
572 module:log("info", "Deleted all expired messages"); |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
573 end |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
574 else |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
575 module:log("error", "Could not delete messages: %s", err); |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
576 end |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
577 cleanup_done(); |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
578 return; |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
579 end |
|
6e1af07921d1
mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported
Kim Alvefur <zash@zash.se>
parents:
11875
diff
changeset
|
580 |
|
9879
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
581 local users = {}; |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
582 local cut_off = datestamp(os.time() - cleanup_after); |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
583 for date in cleanup_storage:users() do |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
584 if date <= cut_off then |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
585 module:log("debug", "Messages from %q should be expired", date); |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
586 local messages_this_day = cleanup_storage:get(date); |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
587 if messages_this_day then |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
588 for user in pairs(messages_this_day) do |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
589 users[user] = true; |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
590 end |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
591 if date < cut_off then |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
592 -- Messages from the same day as the cut-off might not have expired yet, |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
593 -- but all earlier will have, so clear storage for those days. |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
594 cleanup_storage:set(date, nil); |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
595 end |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
596 end |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
597 end |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
598 end |
|
9879
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
599 local sum, num_users = 0, 0; |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
600 for user in pairs(users) do |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
601 local ok, err = archive:delete(user, { ["end"] = os.time() - cleanup_after; }) |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
602 if ok then |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
603 num_users = num_users + 1; |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
604 sum = sum + (tonumber(ok) or 0); |
|
10524
7c29a6e652d2
mod_mam: Log error when unable to delete old messages (fix #1479) [luacheck]
Kim Alvefur <zash@zash.se>
parents:
10523
diff
changeset
|
605 else |
|
10525
9cf7d9761ca2
mod_mam: Schedule cleanup again if unable to delete messages
Kim Alvefur <zash@zash.se>
parents:
10524
diff
changeset
|
606 cleanup_map:set(cut_off, user, true); |
|
10524
7c29a6e652d2
mod_mam: Log error when unable to delete old messages (fix #1479) [luacheck]
Kim Alvefur <zash@zash.se>
parents:
10523
diff
changeset
|
607 module:log("error", "Could not delete messages for user '%s': %s", user, err); |
|
9879
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
608 end |
|
14003
2c95239d0b92
mod_mam: Use util.async.sleep() helper (same functionality, less code)
Matthew Wild <mwild1@gmail.com>
parents:
13992
diff
changeset
|
609 async.sleep(0.1); |
|
9879
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
610 end |
|
ddc07fb8dcd4
mod_mam: Perform message expiry based on building an index by date (backport of 39ee70fbb009 from trunk)
Kim Alvefur <zash@zash.se>
parents:
9555
diff
changeset
|
611 module:log("info", "Deleted %d expired messages for %d users", sum, num_users); |
|
9757
03ed7f10d8da
mod_mam: Measure how long it takes to run the message expiry job job
Kim Alvefur <zash@zash.se>
parents:
9752
diff
changeset
|
612 cleanup_done(); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
613 end); |
|
8132
6ddddfe05a74
mod_mam: Don't ask the storage backend to count all items when expiry is disabled
Kim Alvefur <zash@zash.se>
parents:
8047
diff
changeset
|
614 else |
|
8576
07ff7b8b702b
mod_mam: Log a debug message if archive expiry has been disabled
Kim Alvefur <zash@zash.se>
parents:
8575
diff
changeset
|
615 module:log("debug", "Archive expiry disabled"); |
|
8132
6ddddfe05a74
mod_mam: Don't ask the storage backend to count all items when expiry is disabled
Kim Alvefur <zash@zash.se>
parents:
8047
diff
changeset
|
616 -- Don't ask the backend to count the potentially unbounded number of items, |
|
6ddddfe05a74
mod_mam: Don't ask the storage backend to count all items when expiry is disabled
Kim Alvefur <zash@zash.se>
parents:
8047
diff
changeset
|
617 -- it'll get slow. |
|
8577
75d5eee6fcdf
mod_mam: Add an option for whether to include 'total' counts by default in queries
Kim Alvefur <zash@zash.se>
parents:
8576
diff
changeset
|
618 use_total = module:get_option_boolean("mam_include_total", false); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
619 end |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
620 |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
621 -- Stanzas sent by local clients |
|
7840
92b6aa3ea2ce
mod_mam: Decrease priority to zero
Kim Alvefur <zash@zash.se>
parents:
7839
diff
changeset
|
622 module:hook("pre-message/bare", c2s_message_handler, 0); |
|
92b6aa3ea2ce
mod_mam: Decrease priority to zero
Kim Alvefur <zash@zash.se>
parents:
7839
diff
changeset
|
623 module:hook("pre-message/full", c2s_message_handler, 0); |
| 7905 | 624 -- Stanzas to local clients |
|
7840
92b6aa3ea2ce
mod_mam: Decrease priority to zero
Kim Alvefur <zash@zash.se>
parents:
7839
diff
changeset
|
625 module:hook("message/bare", message_handler, 0); |
|
92b6aa3ea2ce
mod_mam: Decrease priority to zero
Kim Alvefur <zash@zash.se>
parents:
7839
diff
changeset
|
626 module:hook("message/full", message_handler, 0); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
627 |
|
11281
142fb655b885
mod_mam: Advertise extended MAM when archive storage is capable
Kim Alvefur <zash@zash.se>
parents:
11280
diff
changeset
|
628 local advertise_extended = archive.caps and archive.caps.full_id_range and archive.caps.ids; |
|
11268
e3f6f0b39e7b
mod_mam: Advertise extended MAM 0.7.x behind a feature flag
Kim Alvefur <zash@zash.se>
parents:
11260
diff
changeset
|
629 |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
630 module:hook("account-disco-info", function(event) |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
631 (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up(); |
|
11268
e3f6f0b39e7b
mod_mam: Advertise extended MAM 0.7.x behind a feature flag
Kim Alvefur <zash@zash.se>
parents:
11260
diff
changeset
|
632 if advertise_extended then |
|
e3f6f0b39e7b
mod_mam: Advertise extended MAM 0.7.x behind a feature flag
Kim Alvefur <zash@zash.se>
parents:
11260
diff
changeset
|
633 (event.reply or event.stanza):tag("feature", {var=xmlns_mam_ext}):up(); |
|
e3f6f0b39e7b
mod_mam: Advertise extended MAM 0.7.x behind a feature flag
Kim Alvefur <zash@zash.se>
parents:
11260
diff
changeset
|
634 end |
|
7891
01d2a2af3146
mod_mam: Advertise Stanza ID support (XEP-0359) (thanks iNPUTmice)
Kim Alvefur <zash@zash.se>
parents:
7890
diff
changeset
|
635 (event.reply or event.stanza):tag("feature", {var=xmlns_st_id}):up(); |
|
7836
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
636 end); |
|
30fac9154fd4
mod_mam: Import from prosody-modules
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
637 |
