Comparison

plugins/mod_pubsub/mod_pubsub.lua @ 11631:6641ca266d94

mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items' Fixes #1643 API change: The argument to archive_itemstore() changes type to integer
author Kim Alvefur <zash@zash.se>
date Wed, 09 Jun 2021 15:58:49 +0200
parent 11202:58492b4b85ea
child 11715:ddd6e21e58bf
comparison
equal deleted inserted replaced
11630:855b065d5fd6 11631:6641ca266d94
37 -- A nodestore supports the following methods: 37 -- A nodestore supports the following methods:
38 -- set(node_name, node_data) 38 -- set(node_name, node_data)
39 -- get(node_name) 39 -- get(node_name)
40 -- users(): iterator over (node_name) 40 -- users(): iterator over (node_name)
41 41
42 local max_max_items = module:get_option_number("pubsub_max_items", 256);
43
44 local function tonumber_max_items(n)
45 if n == "max" then
46 return max_max_items;
47 end
48 return tonumber(n);
49 end
42 50
43 local node_store = module:open_store(module.name.."_nodes"); 51 local node_store = module:open_store(module.name.."_nodes");
44 52
45 local function create_simple_itemstore(node_config, node_name) --> util.cache like object 53 local function create_simple_itemstore(node_config, node_name) --> util.cache like object
46 local driver = storagemanager.get_driver(module.host, "pubsub_data"); 54 local driver = storagemanager.get_driver(module.host, "pubsub_data");
47 local archive = driver:open("pubsub_"..node_name, "archive"); 55 local archive = driver:open("pubsub_"..node_name, "archive");
48 return lib_pubsub.archive_itemstore(archive, node_config, nil, node_name); 56 local max_items = tonumber_max_items(node_config["max_items"]);
57 return lib_pubsub.archive_itemstore(archive, max_items, nil, node_name);
49 end 58 end
50 59
51 function simple_broadcast(kind, node, jids, item, actor, node_obj) 60 function simple_broadcast(kind, node, jids, item, actor, node_obj)
52 if node_obj then 61 if node_obj then
53 if node_obj.config["notify_"..kind] == false then 62 if node_obj.config["notify_"..kind] == false then
97 new_stanza.attr.to = jid; 106 new_stanza.attr.to = jid;
98 module:send(new_stanza); 107 module:send(new_stanza);
99 end 108 end
100 end 109 end
101 110
102 local max_max_items = module:get_option_number("pubsub_max_items", 256);
103 function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor 111 function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor
104 if (new_config["max_items"] or 1) > max_max_items then 112 if (tonumber_max_items(new_config["max_items"]) or 1) > max_max_items then
105 return false; 113 return false;
106 end 114 end
107 if new_config["access_model"] ~= "whitelist" 115 if new_config["access_model"] ~= "whitelist"
108 and new_config["access_model"] ~= "open" then 116 and new_config["access_model"] ~= "open" then
109 return false; 117 return false;