diff options
author | Kim Alvefur <zash@zash.se> | 2021-06-09 15:58:49 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-06-09 15:58:49 +0200 |
commit | c880dee2af4b1f5e184c3a3c7f70036694d9c1f8 (patch) | |
tree | f0bcecd7be12b067e31e7aa05354fc17a2d9cc64 /plugins | |
parent | 351a197fbdd99b11505c283ae8c3f414bee38885 (diff) | |
download | prosody-c880dee2af4b1f5e184c3a3c7f70036694d9c1f8.tar.gz prosody-c880dee2af4b1f5e184c3a3c7f70036694d9c1f8.zip |
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Fixes #1643
API change: The argument to archive_itemstore() changes type to integer
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mod_pep.lua | 14 | ||||
-rw-r--r-- | plugins/mod_pubsub/mod_pubsub.lua | 14 | ||||
-rw-r--r-- | plugins/mod_pubsub/pubsub.lib.lua | 7 |
3 files changed, 25 insertions, 10 deletions
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index da74639e..f9e2f808 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -35,6 +35,13 @@ local known_nodes = module:open_store("pep"); local max_max_items = module:get_option_number("pep_max_items", 256); +local function tonumber_max_items(n) + if n == "max" then + return max_max_items; + end + return tonumber(n); +end + function module.save() return { services = services; @@ -56,7 +63,7 @@ function is_item_stanza(item) end function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor - if (new_config["max_items"] or 1) > max_max_items then + if (tonumber_max_items(new_config["max_items"]) or 1) > max_max_items then return false; end if new_config["access_model"] ~= "presence" @@ -102,13 +109,14 @@ end local function simple_itemstore(username) local driver = storagemanager.get_driver(module.host, "pep_data"); return function (config, node) + local max_items = tonumber_max_items(config["max_items"]); if config["persist_items"] then module:log("debug", "Creating new persistent item store for user %s, node %q", username, node); local archive = driver:open("pep_"..node, "archive"); - return lib_pubsub.archive_itemstore(archive, config, username, node, false); + return lib_pubsub.archive_itemstore(archive, max_items, username, node, false); else module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node); - return cache.new(tonumber(config["max_items"])); + return cache.new(max_items); end end end diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua index 2c3413fd..19834ad4 100644 --- a/plugins/mod_pubsub/mod_pubsub.lua +++ b/plugins/mod_pubsub/mod_pubsub.lua @@ -39,13 +39,22 @@ end -- get(node_name) -- users(): iterator over (node_name) +local max_max_items = module:get_option_number("pubsub_max_items", 256); + +local function tonumber_max_items(n) + if n == "max" then + return max_max_items; + end + return tonumber(n); +end local node_store = module:open_store(module.name.."_nodes"); local function create_simple_itemstore(node_config, node_name) --> util.cache like object local driver = storagemanager.get_driver(module.host, "pubsub_data"); local archive = driver:open("pubsub_"..node_name, "archive"); - return lib_pubsub.archive_itemstore(archive, node_config, nil, node_name); + local max_items = tonumber_max_items(node_config["max_items"]); + return lib_pubsub.archive_itemstore(archive, max_items, nil, node_name); end function simple_broadcast(kind, node, jids, item, actor, node_obj) @@ -99,9 +108,8 @@ function simple_broadcast(kind, node, jids, item, actor, node_obj) end end -local max_max_items = module:get_option_number("pubsub_max_items", 256); function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor - if (new_config["max_items"] or 1) > max_max_items then + if (tonumber_max_items(new_config["max_items"]) or 1) > max_max_items then return false; end if new_config["access_model"] ~= "whitelist" diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua index b53e0689..e7fa715d 100644 --- a/plugins/mod_pubsub/pubsub.lib.lua +++ b/plugins/mod_pubsub/pubsub.lib.lua @@ -83,7 +83,7 @@ local node_config_form = dataform { }; { type = "text-single"; - datatype = "xs:integer"; + datatype = "pubsub:integer-or-max"; name = "max_items"; var = "pubsub#max_items"; label = "Max # of items to persist"; @@ -801,10 +801,9 @@ local function create_encapsulating_item(id, payload) return item; end -local function archive_itemstore(archive, config, user, node) - module:log("debug", "Creation of archive itemstore for node %s with config %q", node, config); +local function archive_itemstore(archive, max_items, user, node) + module:log("debug", "Creation of archive itemstore for node %s with limit %d", node, max_items); local get_set = {}; - local max_items = config["max_items"]; function get_set:items() -- luacheck: ignore 212/self local data, err = archive:find(user, { limit = tonumber(max_items); |