comparison plugins/mod_pubsub/mod_pubsub.lua @ 12960:31b22cc221b5

mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher This matches ejabberd's behaviour, using the 'pubsub#itemreply' config option. Although the current definition of this option in the specification is not as clear as it could be, I think matching what existing deployments do is the best option to resolve the ambiguity and reduce fragmentation. We should update the spec to be clearer about how to use and interpret this option. The 'expose_publisher' option for mod_pubsub is now an override (always expose or never expose). If unset, it will use the per-node config (which defaults to not exposing). Thanks to Link Mauve, edhelas and goffi for sparking this feature.
author Matthew Wild <mwild1@gmail.com>
date Wed, 22 Mar 2023 11:39:19 +0000
parents 9061f9621330
children 74b9e05af71e
comparison
equal deleted inserted replaced
12959:e331210beeb2 12960:31b22cc221b5
10 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; 10 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
11 11
12 local autocreate_on_publish = module:get_option_boolean("autocreate_on_publish", false); 12 local autocreate_on_publish = module:get_option_boolean("autocreate_on_publish", false);
13 local autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe", false); 13 local autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe", false);
14 local pubsub_disco_name = module:get_option_string("name", "Prosody PubSub Service"); 14 local pubsub_disco_name = module:get_option_string("name", "Prosody PubSub Service");
15 local expose_publisher = module:get_option_boolean("expose_publisher", false) 15 local service_expose_publisher = module:get_option_boolean("expose_publisher")
16 16
17 local service; 17 local service;
18 18
19 local lib_pubsub = module:require "pubsub"; 19 local lib_pubsub = module:require "pubsub";
20 20
79 item.attr.xmlns = nil; -- Clear the pubsub namespace 79 item.attr.xmlns = nil; -- Clear the pubsub namespace
80 if kind == "items" then 80 if kind == "items" then
81 if node_obj and node_obj.config.include_payload == false then 81 if node_obj and node_obj.config.include_payload == false then
82 item:maptags(function () return nil; end); 82 item:maptags(function () return nil; end);
83 end 83 end
84 if not expose_publisher then 84 local node_expose_publisher = service_expose_publisher;
85 if node_expose_publisher == nil and node_obj and node_obj.config.itemreply == "publisher" then
86 node_expose_publisher = true;
87 end
88 if not node_expose_publisher then
85 item.attr.publisher = nil; 89 item.attr.publisher = nil;
86 elseif not item.attr.publisher and actor ~= true then 90 elseif not item.attr.publisher and actor ~= true then
87 item.attr.publisher = service.config.normalize_jid(actor); 91 item.attr.publisher = service.config.normalize_jid(actor);
88 end 92 end
89 end 93 end
190 194
191 function set_service(new_service) 195 function set_service(new_service)
192 service = new_service; 196 service = new_service;
193 service.config.autocreate_on_publish = autocreate_on_publish; 197 service.config.autocreate_on_publish = autocreate_on_publish;
194 service.config.autocreate_on_subscribe = autocreate_on_subscribe; 198 service.config.autocreate_on_subscribe = autocreate_on_subscribe;
195 service.config.expose_publisher = expose_publisher; 199 service.config.expose_publisher = service_expose_publisher;
196 200
197 service.config.nodestore = node_store; 201 service.config.nodestore = node_store;
198 service.config.itemstore = create_simple_itemstore; 202 service.config.itemstore = create_simple_itemstore;
199 service.config.broadcaster = simple_broadcast; 203 service.config.broadcaster = simple_broadcast;
200 service.config.itemcheck = is_item_stanza; 204 service.config.itemcheck = is_item_stanza;
217 if module.reloading then return; end 221 if module.reloading then return; end
218 222
219 set_service(pubsub.new({ 223 set_service(pubsub.new({
220 autocreate_on_publish = autocreate_on_publish; 224 autocreate_on_publish = autocreate_on_publish;
221 autocreate_on_subscribe = autocreate_on_subscribe; 225 autocreate_on_subscribe = autocreate_on_subscribe;
222 expose_publisher = expose_publisher; 226 expose_publisher = service_expose_publisher;
223 227
224 node_defaults = { 228 node_defaults = {
225 ["persist_items"] = true; 229 ["persist_items"] = true;
226 }; 230 };
227 max_items = max_max_items; 231 max_items = max_max_items;