Software / code / prosody
Comparison
plugins/mod_pep.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 | 11567:c471e19a238e |
| child | 11722:bc2d3f110a39 |
comparison
equal
deleted
inserted
replaced
| 11630:855b065d5fd6 | 11631:6641ca266d94 |
|---|---|
| 33 local node_config = module:open_store("pep", "map"); | 33 local node_config = module:open_store("pep", "map"); |
| 34 local known_nodes = module:open_store("pep"); | 34 local known_nodes = module:open_store("pep"); |
| 35 | 35 |
| 36 local max_max_items = module:get_option_number("pep_max_items", 256); | 36 local max_max_items = module:get_option_number("pep_max_items", 256); |
| 37 | 37 |
| 38 local function tonumber_max_items(n) | |
| 39 if n == "max" then | |
| 40 return max_max_items; | |
| 41 end | |
| 42 return tonumber(n); | |
| 43 end | |
| 44 | |
| 38 function module.save() | 45 function module.save() |
| 39 return { | 46 return { |
| 40 services = services; | 47 services = services; |
| 41 recipients = recipients; | 48 recipients = recipients; |
| 42 }; | 49 }; |
| 54 function is_item_stanza(item) | 61 function is_item_stanza(item) |
| 55 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item" and #item.tags == 1; | 62 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item" and #item.tags == 1; |
| 56 end | 63 end |
| 57 | 64 |
| 58 function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor | 65 function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor |
| 59 if (new_config["max_items"] or 1) > max_max_items then | 66 if (tonumber_max_items(new_config["max_items"]) or 1) > max_max_items then |
| 60 return false; | 67 return false; |
| 61 end | 68 end |
| 62 if new_config["access_model"] ~= "presence" | 69 if new_config["access_model"] ~= "presence" |
| 63 and new_config["access_model"] ~= "whitelist" | 70 and new_config["access_model"] ~= "whitelist" |
| 64 and new_config["access_model"] ~= "open" then | 71 and new_config["access_model"] ~= "open" then |
| 100 end | 107 end |
| 101 | 108 |
| 102 local function simple_itemstore(username) | 109 local function simple_itemstore(username) |
| 103 local driver = storagemanager.get_driver(module.host, "pep_data"); | 110 local driver = storagemanager.get_driver(module.host, "pep_data"); |
| 104 return function (config, node) | 111 return function (config, node) |
| 112 local max_items = tonumber_max_items(config["max_items"]); | |
| 105 if config["persist_items"] then | 113 if config["persist_items"] then |
| 106 module:log("debug", "Creating new persistent item store for user %s, node %q", username, node); | 114 module:log("debug", "Creating new persistent item store for user %s, node %q", username, node); |
| 107 local archive = driver:open("pep_"..node, "archive"); | 115 local archive = driver:open("pep_"..node, "archive"); |
| 108 return lib_pubsub.archive_itemstore(archive, config, username, node, false); | 116 return lib_pubsub.archive_itemstore(archive, max_items, username, node, false); |
| 109 else | 117 else |
| 110 module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node); | 118 module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node); |
| 111 return cache.new(tonumber(config["max_items"])); | 119 return cache.new(max_items); |
| 112 end | 120 end |
| 113 end | 121 end |
| 114 end | 122 end |
| 115 | 123 |
| 116 local function get_broadcaster(username) | 124 local function get_broadcaster(username) |