comparison plugins/mod_pep_plus.lua @ 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 d00ea07de9a0
children 4a576c39bb2f
comparison
equal deleted inserted replaced
8948:3be8799263f3 8949:9194431b6447
21 local recipients = {}; 21 local recipients = {};
22 local hash_map = {}; 22 local hash_map = {};
23 23
24 local host = module.host; 24 local host = module.host;
25 25
26 local known_nodes_map = module:open_store("pep", "map"); 26 local node_config = module:open_store("pep", "map");
27 local known_nodes = module:open_store("pep"); 27 local known_nodes = module:open_store("pep");
28 28
29 function module.save() 29 function module.save()
30 return { services = services }; 30 return { services = services };
31 end 31 end
43 local recipient_bare = jid_bare(recipient); 43 local recipient_bare = jid_bare(recipient);
44 if (recipient_bare == user_bare) then return true; end 44 if (recipient_bare == user_bare) then return true; end
45 return is_contact_subscribed(username, host, recipient_bare); 45 return is_contact_subscribed(username, host, recipient_bare);
46 end 46 end
47 47
48 local function nodestore(username)
49 -- luacheck: ignore 212/self
50 local store = {};
51 function store:get(node)
52 local data, err = node_config:get(username, node)
53 if data == true then
54 -- COMPAT Previously stored only a boolean representing 'persist_items'
55 data = {
56 name = node;
57 config = {};
58 subscribers = {};
59 affiliations = {};
60 };
61 end
62 return data, err;
63 end
64 function store:set(node, data)
65 return node_config:set(username, node, data);
66 end
67 function store:users()
68 return pairs(known_nodes:get(username) or {});
69 end
70 return store;
71 end
72
48 local function simple_itemstore(username) 73 local function simple_itemstore(username)
49 return function (config, node) 74 return function (config, node)
50 if config["persist_items"] then 75 if config["persist_items"] then
51 module:log("debug", "Creating new persistent item store for user %s, node %q", username, node); 76 module:log("debug", "Creating new persistent item store for user %s, node %q", username, node);
52 known_nodes_map:set(username, node, true);
53 local archive = module:open_store("pep_"..node, "archive"); 77 local archive = module:open_store("pep_"..node, "archive");
54 return lib_pubsub.archive_itemstore(archive, config, username, node, false); 78 return lib_pubsub.archive_itemstore(archive, config, username, node, false);
55 else 79 else
56 module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node); 80 module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node);
57 known_nodes_map:set(username, node, nil);
58 return cache.new(tonumber(config["max_items"])); 81 return cache.new(tonumber(config["max_items"]));
59 end 82 end
60 end 83 end
61 end 84 end
62 85
188 }; 211 };
189 212
190 autocreate_on_publish = true; 213 autocreate_on_publish = true;
191 autocreate_on_subscribe = true; 214 autocreate_on_subscribe = true;
192 215
216 nodestore = nodestore(username);
193 itemstore = simple_itemstore(username); 217 itemstore = simple_itemstore(username);
194 broadcaster = get_broadcaster(username); 218 broadcaster = get_broadcaster(username);
195 itemcheck = is_item_stanza; 219 itemcheck = is_item_stanza;
196 get_affiliation = function (jid) 220 get_affiliation = function (jid)
197 if jid_bare(jid) == user_bare then 221 if jid_bare(jid) == user_bare then