# HG changeset patch # User Kim Alvefur # Date 1623247129 -7200 # Node ID 6641ca266d94dbabce4fc36935316092f5c13633 # Parent 855b065d5fd64e3393869d2ab4222802944ffe7d mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items' Fixes #1643 API change: The argument to archive_itemstore() changes type to integer diff -r 855b065d5fd6 -r 6641ca266d94 doc/doap.xml --- a/doc/doap.xml Fri Sep 18 12:18:51 2020 +0200 +++ b/doc/doap.xml Wed Jun 09 15:58:49 2021 +0200 @@ -158,7 +158,7 @@ - 1.15.8 + 1.20.0 0.9.0 partial diff -r 855b065d5fd6 -r 6641ca266d94 plugins/mod_pep.lua --- a/plugins/mod_pep.lua Fri Sep 18 12:18:51 2020 +0200 +++ b/plugins/mod_pep.lua Wed Jun 09 15:58:49 2021 +0200 @@ -35,6 +35,13 @@ 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 @@ 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 @@ 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 -r 855b065d5fd6 -r 6641ca266d94 plugins/mod_pubsub/mod_pubsub.lua --- a/plugins/mod_pubsub/mod_pubsub.lua Fri Sep 18 12:18:51 2020 +0200 +++ b/plugins/mod_pubsub/mod_pubsub.lua Wed Jun 09 15:58:49 2021 +0200 @@ -39,13 +39,22 @@ -- 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 @@ 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 -r 855b065d5fd6 -r 6641ca266d94 plugins/mod_pubsub/pubsub.lib.lua --- a/plugins/mod_pubsub/pubsub.lib.lua Fri Sep 18 12:18:51 2020 +0200 +++ b/plugins/mod_pubsub/pubsub.lib.lua Wed Jun 09 15:58:49 2021 +0200 @@ -83,7 +83,7 @@ }; { 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 @@ 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); diff -r 855b065d5fd6 -r 6641ca266d94 spec/scansion/pep_pubsub_max.scs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/scansion/pep_pubsub_max.scs Wed Jun 09 15:58:49 2021 +0200 @@ -0,0 +1,47 @@ +# PEP max_items=max + +[Client] Romeo + jid: pep-test-maxitems@localhost + password: password + +----- + +Romeo connects + +Romeo sends: + + + + + + Hello + + + + + + + http://jabber.org/protocol/pubsub#publish-options + + + true + + + open + + + max + + + + + + +Romeo receives: + + + + + + + diff -r 855b065d5fd6 -r 6641ca266d94 spec/scansion/pubsub_config.scs --- a/spec/scansion/pubsub_config.scs Fri Sep 18 12:18:51 2020 +0200 +++ b/spec/scansion/pubsub_config.scs Wed Jun 09 15:58:49 2021 +0200 @@ -48,7 +48,7 @@ - + 1 @@ -124,7 +124,7 @@ - + 1 diff -r 855b065d5fd6 -r 6641ca266d94 spec/scansion/pubsub_multi_items.scs --- a/spec/scansion/pubsub_multi_items.scs Fri Sep 18 12:18:51 2020 +0200 +++ b/spec/scansion/pubsub_multi_items.scs Wed Jun 09 15:58:49 2021 +0200 @@ -43,7 +43,7 @@ - + 20 diff -r 855b065d5fd6 -r 6641ca266d94 spec/scansion/pubsub_preconditions.scs --- a/spec/scansion/pubsub_preconditions.scs Fri Sep 18 12:18:51 2020 +0200 +++ b/spec/scansion/pubsub_preconditions.scs Wed Jun 09 15:58:49 2021 +0200 @@ -47,7 +47,7 @@ - + 1 @@ -123,7 +123,7 @@ - + 1