diff options
author | Kim Alvefur <zash@zash.se> | 2018-07-01 03:43:14 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2018-07-01 03:43:14 +0200 |
commit | e578e49be41e03edcef5fee0a3a509d8027333fd (patch) | |
tree | c28660716404fdc10e80d8c867bf127a02cae314 /plugins/mod_pep_plus.lua | |
parent | 6d7e7a81e26b6afbef5ac177ba30713528e55450 (diff) | |
download | prosody-e578e49be41e03edcef5fee0a3a509d8027333fd.tar.gz prosody-e578e49be41e03edcef5fee0a3a509d8027333fd.zip |
mod_pep_plus: Support persistence of node configuration
Diffstat (limited to 'plugins/mod_pep_plus.lua')
-rw-r--r-- | plugins/mod_pep_plus.lua | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/plugins/mod_pep_plus.lua b/plugins/mod_pep_plus.lua index 92a41719..e06a65b3 100644 --- a/plugins/mod_pep_plus.lua +++ b/plugins/mod_pep_plus.lua @@ -23,7 +23,7 @@ local hash_map = {}; 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 @@ local function subscription_presence(username, recipient) 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 @@ function get_pep_service(username) autocreate_on_publish = true; autocreate_on_subscribe = true; + nodestore = nodestore(username); itemstore = simple_itemstore(username); broadcaster = get_broadcaster(username); itemcheck = is_item_stanza; |