Changeset

8949:9194431b6447

mod_pep_plus: Support persistence of node configuration
author Kim Alvefur <zash@zash.se>
date Sun, 01 Jul 2018 03:43:14 +0200
parents 8948:3be8799263f3
children 8950:03ba5b4f131a
files plugins/mod_pep_plus.lua
diffstat 1 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_pep_plus.lua	Thu Jun 28 11:05:00 2018 +0200
+++ b/plugins/mod_pep_plus.lua	Sun Jul 01 03:43:14 2018 +0200
@@ -23,7 +23,7 @@
 
 local host = module.host;
 
-local known_nodes_map = module:open_store("pep", "map");
+local node_config = module:open_store("pep", "map");
 local known_nodes = module:open_store("pep");
 
 function module.save()
@@ -45,16 +45,39 @@
 	return is_contact_subscribed(username, host, recipient_bare);
 end
 
+local function nodestore(username)
+	-- luacheck: ignore 212/self
+	local store = {};
+	function store:get(node)
+		local data, err = node_config:get(username, node)
+		if data == true then
+			-- COMPAT Previously stored only a boolean representing 'persist_items'
+			data = {
+				name = node;
+				config = {};
+				subscribers = {};
+				affiliations = {};
+			};
+		end
+		return data, err;
+	end
+	function store:set(node, data)
+		return node_config:set(username, node, data);
+	end
+	function store:users()
+		return pairs(known_nodes:get(username) or {});
+	end
+	return store;
+end
+
 local function simple_itemstore(username)
 	return function (config, node)
 		if config["persist_items"] then
 			module:log("debug", "Creating new persistent item store for user %s, node %q", username, node);
-			known_nodes_map:set(username, node, true);
 			local archive = module:open_store("pep_"..node, "archive");
 			return lib_pubsub.archive_itemstore(archive, config, username, node, false);
 		else
 			module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node);
-			known_nodes_map:set(username, node, nil);
 			return cache.new(tonumber(config["max_items"]));
 		end
 	end
@@ -190,6 +213,7 @@
 		autocreate_on_publish = true;
 		autocreate_on_subscribe = true;
 
+		nodestore = nodestore(username);
 		itemstore = simple_itemstore(username);
 		broadcaster = get_broadcaster(username);
 		itemcheck = is_item_stanza;