1 -- XEP-0313: Message Archive Management for Prosody
2 -- Copyright (C) 2011-2013 Kim Alvefur
4 -- This file is MIT/X11 licensed.
5 -- luacheck: ignore 122/prosody
7 local global_default_policy
= module
:get_option("default_archive_policy", true);
10 -- luacheck: ignore 211/prefs_format
11 local prefs_format
= {
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
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
);
30 user_sessions
.archive_prefs
= user_prefs
;
33 return user_prefs
or { [false] = global_default_policy
};
35 local function set_prefs(user
, user_prefs
)
36 local user_sessions
= sessions
[user
];
38 user_sessions
.archive_prefs
= user_prefs
;
40 return prefs
:set(user
, user_prefs
);