mod_muc_webchat_url: Fix default url
[prosody-modules.git] / mod_mam / mamprefs.lib.lua
blobcd54e0f48bd0e9d53c7dd27ad5560161c913a842
1 -- XEP-0313: Message Archive Management for Prosody
2 -- Copyright (C) 2011-2013 Kim Alvefur
3 --
4 -- This file is MIT/X11 licensed.
5 -- luacheck: ignore 122/prosody
7 local global_default_policy = module:get_option("default_archive_policy", true);
9 do
10 -- luacheck: ignore 211/prefs_format
11 local prefs_format = {
12 [false] = "roster",
13 -- default ::= true | false | "roster"
14 -- true = always, false = never, nil = global default
15 ["romeo@montague.net"] = true, -- always
16 ["montague@montague.net"] = false, -- newer
18 end
20 local sessions = prosody.hosts[module.host].sessions;
21 local archive_store = module:get_option_string("archive_store", "archive");
22 local prefs = module:open_store(archive_store .. "_prefs");
24 local function get_prefs(user)
25 local user_sessions = sessions[user];
26 local user_prefs = user_sessions and user_sessions.archive_prefs
27 if not user_prefs then
28 user_prefs = prefs:get(user);
29 if user_sessions then
30 user_sessions.archive_prefs = user_prefs;
31 end
32 end
33 return user_prefs or { [false] = global_default_policy };
34 end
35 local function set_prefs(user, user_prefs)
36 local user_sessions = sessions[user];
37 if user_sessions then
38 user_sessions.archive_prefs = user_prefs;
39 end
40 return prefs:set(user, user_prefs);
41 end
43 return {
44 get = get_prefs,
45 set = set_prefs,