annotate mod_mam/mamprefs.lib.lua @ 2670:6e01878103c0

mod_smacks: Ignore user when writing or reading session_cache on prosody 0.9 At least under some circumstances it seems that session.username is nil when a user tries to resume his session in prosody 0.9. The username is not relevant when no limiting is done (limiting the number of entries in the session cache is only possible in prosody 0.10), so this commit removes the usage of the username when accessing the prosody 0.9 session cache.
author tmolitor <thilo@eightysoft.de>
date Thu, 06 Apr 2017 02:12:14 +0200
parents d81882aa0e1e
children 9ffb059c9ba5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
431627b07b9f mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents: 1136
diff changeset
27 if not user_prefs and 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
28 user_prefs = prefs:get(user);
431627b07b9f mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents: 1136
diff changeset
29 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
30 end
1153
572b1ad46182 mod_mam/mamprefs.lib: Revert accidentally commited change
Kim Alvefur <zash@zash.se>
parents: 1137
diff changeset
31 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
32 end
1136
a6d4508f7f28 mod_mam/mamprefs.lib: Switch to storagemanager API
Kim Alvefur <zash@zash.se>
parents: 1111
diff changeset
33 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
34 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
35 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
36 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
37 end
1136
a6d4508f7f28 mod_mam/mamprefs.lib: Switch to storagemanager API
Kim Alvefur <zash@zash.se>
parents: 1111
diff changeset
38 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
39 end
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 return {
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 get = get_prefs,
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 set = set_prefs,
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 }