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.lua56
1 files changed, 45 insertions, 11 deletions
diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index c13630c9..be460f72 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -39,16 +39,32 @@ 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
+
+for _, field in ipairs(lib_pubsub.node_config_form) do
+ if field.var == "pubsub#max_items" then
+ field.range_max = max_max_items;
+ break;
+ end
+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)
+function simple_broadcast(kind, node, jids, item, actor, node_obj, service) --luacheck: ignore 431/service
if node_obj then
if node_obj.config["notify_"..kind] == false then
return;
@@ -65,8 +81,10 @@ function simple_broadcast(kind, node, jids, item, actor, node_obj)
if node_obj and node_obj.config.include_payload == false then
item:maptags(function () return nil; end);
end
- if expose_publisher and actor then
- item.attr.publisher = actor
+ if not expose_publisher then
+ item.attr.publisher = nil;
+ elseif not item.attr.publisher then
+ item.attr.publisher = service.config.normalize_jid(actor);
end
end
end
@@ -75,14 +93,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 +117,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 +132,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");
@@ -172,6 +190,17 @@ end
function set_service(new_service)
service = new_service;
+ service.config.autocreate_on_publish = autocreate_on_publish;
+ service.config.autocreate_on_subscribe = autocreate_on_subscribe;
+ service.config.expose_publisher = expose_publisher;
+
+ service.config.nodestore = node_store;
+ service.config.itemstore = create_simple_itemstore;
+ service.config.broadcaster = simple_broadcast;
+ service.config.itemcheck = is_item_stanza;
+ service.config.check_node_config = check_node_config;
+ service.config.get_affiliation = get_affiliation;
+
module.environment.service = service;
add_disco_features_from_service(service);
end
@@ -190,7 +219,11 @@ function module.load()
set_service(pubsub.new({
autocreate_on_publish = autocreate_on_publish;
autocreate_on_subscribe = autocreate_on_subscribe;
+ expose_publisher = expose_publisher;
+ node_defaults = {
+ ["persist_items"] = true;
+ };
nodestore = node_store;
itemstore = create_simple_itemstore;
broadcaster = simple_broadcast;
@@ -198,6 +231,7 @@ function module.load()
check_node_config = check_node_config;
get_affiliation = get_affiliation;
+ jid = module.host;
normalize_jid = jid_bare;
}));
end