Annotate

mod_mam/mamprefs.lib.lua @ 1913:188c38c1a711

mod_http_upload/README: Update with XEP reference, stage, description
author Kim Alvefur <zash@zash.se>
date Sun, 18 Oct 2015 17:25:40 +0200
parent 1153:572b1ad46182
child 2017:d44ac0756c46
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.
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local global_default_policy = module:get_option("default_archive_policy", false);
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 do
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local prefs_format = {
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 [false] = "roster",
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 -- 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
12 -- 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
13 ["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
14 ["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
15 };
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 end
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17
1137
431627b07b9f mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents: 1136
diff changeset
18 local sessions = hosts[module.host].sessions;
1136
a6d4508f7f28 mod_mam/mamprefs.lib: Switch to storagemanager API
Kim Alvefur <zash@zash.se>
parents: 1111
diff changeset
19 local prefs = module:open_store("archive2_prefs");
1137
431627b07b9f mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
Kim Alvefur <zash@zash.se>
parents: 1136
diff changeset
20
1111
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 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
22 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
23 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
24 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
25 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
26 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
27 end
1153
572b1ad46182 mod_mam/mamprefs.lib: Revert accidentally commited change
Kim Alvefur <zash@zash.se>
parents: 1137
diff changeset
28 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
29 end
1136
a6d4508f7f28 mod_mam/mamprefs.lib: Switch to storagemanager API
Kim Alvefur <zash@zash.se>
parents: 1111
diff changeset
30 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
31 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
32 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
33 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
34 end
1136
a6d4508f7f28 mod_mam/mamprefs.lib: Switch to storagemanager API
Kim Alvefur <zash@zash.se>
parents: 1111
diff changeset
35 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
36 end
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 return {
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 get = get_prefs,
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 set = set_prefs,
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 }