Mercurial > prosody-modules
comparison mod_mam/mamprefs.lib.lua @ 1136:a6d4508f7f28
mod_mam/mamprefs.lib: Switch to storagemanager API
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 10 Aug 2013 20:39:24 +0200 |
| parents | bdbf76730f49 |
| children | 431627b07b9f |
comparison
equal
deleted
inserted
replaced
| 1135:0d6ab5e4bc30 | 1136:a6d4508f7f28 |
|---|---|
| 1 -- XEP-0313: Message Archive Management for Prosody | 1 -- XEP-0313: Message Archive Management for Prosody |
| 2 -- Copyright (C) 2011-2012 Kim Alvefur | 2 -- Copyright (C) 2011-2013 Kim Alvefur |
| 3 -- | 3 -- |
| 4 -- This file is MIT/X11 licensed. | 4 -- This file is MIT/X11 licensed. |
| 5 | |
| 6 local host = module.host; | |
| 7 | |
| 8 local dm_load = require "util.datamanager".load; | |
| 9 local dm_store = require "util.datamanager".store; | |
| 10 | 5 |
| 11 local global_default_policy = module:get_option("default_archive_policy", false); | 6 local global_default_policy = module:get_option("default_archive_policy", false); |
| 12 | 7 |
| 13 do | 8 do |
| 14 local prefs_format = { | 9 local prefs_format = { |
| 18 ["romeo@montague.net"] = true, -- always | 13 ["romeo@montague.net"] = true, -- always |
| 19 ["montague@montague.net"] = false, -- newer | 14 ["montague@montague.net"] = false, -- newer |
| 20 }; | 15 }; |
| 21 end | 16 end |
| 22 | 17 |
| 23 local prefs_store = "archive2_prefs"; | 18 local prefs = module:open_store("archive2_prefs"); |
| 24 local function get_prefs(user) | 19 local function get_prefs(user) |
| 25 return dm_load(user, host, prefs_store) or | 20 return prefs:get(user) or { [false] = global_default_policy }; |
| 26 { [false] = global_default_policy }; | |
| 27 end | 21 end |
| 28 local function set_prefs(user, prefs) | 22 local function set_prefs(user, user_prefs) |
| 29 return dm_store(user, host, prefs_store, prefs); | 23 return prefs:set(user, user_prefs); |
| 30 end | 24 end |
| 31 | 25 |
| 32 return { | 26 return { |
| 33 get = get_prefs, | 27 get = get_prefs, |
| 34 set = set_prefs, | 28 set = set_prefs, |
