aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pubsub/mod_pubsub.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_pubsub/mod_pubsub.lua')
-rw-r--r--plugins/mod_pubsub/mod_pubsub.lua25
1 files changed, 17 insertions, 8 deletions
diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index c13630c9..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)
+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)
@@ -75,14 +84,13 @@ function simple_broadcast(kind, node, jids, item, actor, node_obj)
local msg_type = node_obj and node_obj.config.notification_type or "headline";
local message = st.message({ from = module.host, type = msg_type, id = id })
:tag("event", { xmlns = xmlns_pubsub_event })
- :tag(kind, { node = node })
+ :tag(kind, { node = node });
if item then
message:add_child(item);
end
local summary;
- -- Compose a sensible textual representation of at least Atom payloads
if item and item.tags[1] then
local payload = item.tags[1];
summary = module:fire_event("pubsub-summary/"..payload.attr.xmlns, {
@@ -100,12 +108,12 @@ 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/actor 212/node
- if (new_config["max_items"] or 1) > max_max_items then
+function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor
+ if (tonumber_max_items(new_config["max_items"]) or 1) > max_max_items then
return false;
end
- if new_config["access_model"] ~= "whitelist" and new_config["access_model"] ~= "open" then
+ if new_config["access_model"] ~= "whitelist"
+ and new_config["access_model"] ~= "open" then
return false;
end
return true;
@@ -115,6 +123,7 @@ function is_item_stanza(item)
return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item" and #item.tags == 1;
end
+-- Compose a textual representation of Atom payloads
module:hook("pubsub-summary/http://www.w3.org/2005/Atom", function (event)
local payload = event.payload;
local title = payload:get_child_text("title");