Changeset

1111:bdbf76730f49

mod_mam: Split out preference functions into a lib for easy reuse
author Kim Alvefur <zash@zash.se>
date Fri, 12 Jul 2013 22:46:15 +0200
parents 1110:97e238ce37ce
children 1112:1dc07833355e
files mod_mam/mamprefs.lib.lua mod_mam/mod_mam.lua
diffstat 2 files changed, 37 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_mam/mamprefs.lib.lua	Fri Jul 12 22:46:15 2013 +0200
@@ -0,0 +1,35 @@
+-- XEP-0313: Message Archive Management for Prosody
+-- Copyright (C) 2011-2012 Kim Alvefur
+--
+-- This file is MIT/X11 licensed.
+
+local host = module.host;
+
+local dm_load = require "util.datamanager".load;
+local dm_store = require "util.datamanager".store;
+
+local global_default_policy = module:get_option("default_archive_policy", false);
+
+do
+	local prefs_format = {
+		[false] = "roster",
+		-- default ::= true | false | "roster"
+		-- true = always, false = never, nil = global default
+		["romeo@montague.net"] = true, -- always
+		["montague@montague.net"] = false, -- newer
+	};
+end
+
+local prefs_store = "archive2_prefs";
+local function get_prefs(user)
+	return dm_load(user, host, prefs_store) or
+		{ [false] = global_default_policy };
+end
+local function set_prefs(user, prefs)
+	return dm_store(user, host, prefs_store, prefs);
+end
+
+return {
+	get = get_prefs,
+	set = set_prefs,
+}
--- a/mod_mam/mod_mam.lua	Fri Jul 12 01:28:48 2013 +0200
+++ b/mod_mam/mod_mam.lua	Fri Jul 12 22:46:15 2013 +0200
@@ -9,13 +9,13 @@
 
 local st = require "util.stanza";
 local rsm = module:require "rsm";
+local prefs = module:require"mamprefs";
+local set_prefs, get_prefs = prefs.set, prefs.get;
 local jid_bare = require "util.jid".bare;
 local jid_split = require "util.jid".split;
 local jid_prep = require "util.jid".prep;
 local host = module.host;
 
-local dm_load = require "util.datamanager".load;
-local dm_store = require "util.datamanager".store;
 local dm_list_load = require "util.datamanager".list_load;
 local dm_list_append = require "util.datamanager".list_append;
 local rm_load_roster = require "core.rostermanager".load_roster;
@@ -38,26 +38,7 @@
 	roster = "roster",
 }
 
-do
-	local prefs_format = {
-		[false] = "roster",
-		-- default ::= true | false | "roster"
-		-- true = always, false = never, nil = global default
-		["romeo@montague.net"] = true, -- always
-		["montague@montague.net"] = false, -- newer
-	};
-end
-
 local archive_store = "archive2";
-local prefs_store = archive_store .. "_prefs";
-local function get_prefs(user)
-	return dm_load(user, host, prefs_store) or
-		{ [false] = global_default_policy };
-end
-local function set_prefs(user, prefs)
-	return dm_store(user, host, prefs_store, prefs);
-end
-
 
 -- Handle prefs.
 module:hook("iq/self/"..xmlns_mam..":prefs", function(event)