Software /
code /
prosody-modules
Annotate
mod_mam/mamprefs.lib.lua @ 4515:2e33eeafe962
mod_muc_markers: Prevent any markers from reaching the archive, even if untracked
Original intention was to leave alone things that this module isn't
handling. However markers in archives are just problematic without
more advanced logic about what is markable and what is not. It also
requires a more advanced query in mod_muc_rai to determine the latest
markable message instead of the latest archived message.
I'd rather keep the "is archivable" and "is markable" definition the
same for simplicity. I don't want to introduce yet another set of rules
for no reason.
No markers in MAM.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 22 Mar 2021 15:55:02 +0000 |
parent | 2819:9ffb059c9ba5 |
rev | line source |
---|---|
1111
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- XEP-0313: Message Archive Management for Prosody |
1136
a6d4508f7f28
mod_mam/mamprefs.lib: Switch to storagemanager API
Kim Alvefur <zash@zash.se>
parents:
1111
diff
changeset
|
2 -- Copyright (C) 2011-2013 Kim Alvefur |
1111
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 -- |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 -- This file is MIT/X11 licensed. |
2509
34ec7bde5203
mod_mam: Add annotations [luacheck]
Kim Alvefur <zash@zash.se>
parents:
2017
diff
changeset
|
5 -- luacheck: ignore 122/prosody |
1111
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 |
2017
d44ac0756c46
mod_mam: Enable archiving by default, less of a privacy issue if messages expire
Kim Alvefur <zash@zash.se>
parents:
1153
diff
changeset
|
7 local global_default_policy = module:get_option("default_archive_policy", true); |
1111
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 do |
2509
34ec7bde5203
mod_mam: Add annotations [luacheck]
Kim Alvefur <zash@zash.se>
parents:
2017
diff
changeset
|
10 -- luacheck: ignore 211/prefs_format |
1111
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local prefs_format = { |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 [false] = "roster", |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 -- default ::= true | false | "roster" |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 -- true = always, false = never, nil = global default |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 ["romeo@montague.net"] = true, -- always |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 ["montague@montague.net"] = false, -- newer |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 }; |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 end |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 |
2509
34ec7bde5203
mod_mam: Add annotations [luacheck]
Kim Alvefur <zash@zash.se>
parents:
2017
diff
changeset
|
20 local sessions = prosody.hosts[module.host].sessions; |
2510
d81882aa0e1e
mod_mam: Make the store configurable to ease move to 0.10 version
Kim Alvefur <zash@zash.se>
parents:
2509
diff
changeset
|
21 local archive_store = module:get_option_string("archive_store", "archive"); |
d81882aa0e1e
mod_mam: Make the store configurable to ease move to 0.10 version
Kim Alvefur <zash@zash.se>
parents:
2509
diff
changeset
|
22 local prefs = module:open_store(archive_store .. "_prefs"); |
1137
431627b07b9f
mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents:
1136
diff
changeset
|
23 |
1111
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 local function get_prefs(user) |
1137
431627b07b9f
mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents:
1136
diff
changeset
|
25 local user_sessions = sessions[user]; |
431627b07b9f
mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents:
1136
diff
changeset
|
26 local user_prefs = user_sessions and user_sessions.archive_prefs |
2819
9ffb059c9ba5
mod_mam: Load archiving preferes for offline users (fixes #1024)
Kim Alvefur <zash@zash.se>
parents:
2510
diff
changeset
|
27 if not user_prefs then |
1137
431627b07b9f
mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents:
1136
diff
changeset
|
28 user_prefs = prefs:get(user); |
2819
9ffb059c9ba5
mod_mam: Load archiving preferes for offline users (fixes #1024)
Kim Alvefur <zash@zash.se>
parents:
2510
diff
changeset
|
29 if user_sessions then |
9ffb059c9ba5
mod_mam: Load archiving preferes for offline users (fixes #1024)
Kim Alvefur <zash@zash.se>
parents:
2510
diff
changeset
|
30 user_sessions.archive_prefs = user_prefs; |
9ffb059c9ba5
mod_mam: Load archiving preferes for offline users (fixes #1024)
Kim Alvefur <zash@zash.se>
parents:
2510
diff
changeset
|
31 end |
1137
431627b07b9f
mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents:
1136
diff
changeset
|
32 end |
1153
572b1ad46182
mod_mam/mamprefs.lib: Revert accidentally commited change
Kim Alvefur <zash@zash.se>
parents:
1137
diff
changeset
|
33 return user_prefs or { [false] = global_default_policy }; |
1111
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
1136
a6d4508f7f28
mod_mam/mamprefs.lib: Switch to storagemanager API
Kim Alvefur <zash@zash.se>
parents:
1111
diff
changeset
|
35 local function set_prefs(user, user_prefs) |
1137
431627b07b9f
mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents:
1136
diff
changeset
|
36 local user_sessions = sessions[user]; |
431627b07b9f
mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents:
1136
diff
changeset
|
37 if user_sessions then |
431627b07b9f
mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents:
1136
diff
changeset
|
38 user_sessions.archive_prefs = user_prefs; |
431627b07b9f
mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents:
1136
diff
changeset
|
39 end |
1136
a6d4508f7f28
mod_mam/mamprefs.lib: Switch to storagemanager API
Kim Alvefur <zash@zash.se>
parents:
1111
diff
changeset
|
40 return prefs:set(user, user_prefs); |
1111
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 end |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 return { |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 get = get_prefs, |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 set = set_prefs, |
bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 } |