annotate mod_mam/mamprefs.lib.lua @ 1113:f1f0c87cffdd

mod_mam: Neater reply building
author Kim Alvefur <zash@zash.se>
date Fri, 12 Jul 2013 23:18:30 +0200
parents bdbf76730f49
children a6d4508f7f28
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
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 -- Copyright (C) 2011-2012 Kim Alvefur
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 host = module.host;
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 local dm_load = require "util.datamanager".load;
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local dm_store = require "util.datamanager".store;
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 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
12
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 do
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local prefs_format = {
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 [false] = "roster",
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 -- 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
17 -- 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
18 ["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
19 ["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
20 };
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 end
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 local prefs_store = "archive2_prefs";
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)
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 return dm_load(user, host, prefs_store) or
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 { [false] = global_default_policy };
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 local function set_prefs(user, prefs)
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 return dm_store(user, host, prefs_store, prefs);
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 return {
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 get = get_prefs,
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 set = set_prefs,
bdbf76730f49 mod_mam: Split out preference functions into a lib for easy reuse
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 }