Changeset

8306:202b9951b037

mod_pep_plus: Keep track of nodes, and restore them when later
author Kim Alvefur <zash@zash.se>
date Sun, 08 Oct 2017 23:59:13 +0200
parents 8305:ec605946e597
children 8307:94860b5733d3
files plugins/mod_pep_plus.lua
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_pep_plus.lua	Sun Oct 08 23:49:49 2017 +0200
+++ b/plugins/mod_pep_plus.lua	Sun Oct 08 23:59:13 2017 +0200
@@ -22,6 +22,9 @@
 
 local host = module.host;
 
+local known_nodes_map = module:open_store("pep", "map");
+local known_nodes = module:open_store("pep");
+
 function module.save()
 	return { services = services };
 end
@@ -40,6 +43,7 @@
 local function simple_itemstore(username)
 	return function (config, node)
 		module:log("debug", "new simple_itemstore(%q, %q)", username, node);
+		known_nodes_map:set(username, node, true);
 		local archive = module:open_store("pep_"..node, "archive");
 		return lib_pubsub.simple_itemstore(archive, config, username, node, false);
 	end
@@ -186,6 +190,18 @@
 
 		normalize_jid = jid_bare;
 	});
+	local nodes, err = known_nodes:get(username);
+	if nodes then
+		module:log("debug", "Restoring nodes for user %s", username);
+		for node in pairs(nodes) do
+			module:log("debug", "Restoring node %q", node);
+			service:create(node, true);
+		end
+	elseif err then
+		module:log("error", "Could not restore nodes for %s: %s", username, err);
+	else
+		module:log("debug", "No known nodes");
+	end
 	services[username] = service;
 	module:add_item("pep-service", { service = service, jid = user_bare });
 	return service;