Comparison

plugins/mod_pubsub/pubsub.lib.lua @ 11854:b605cbd5f13b

mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436 Default left as 'never' in mod_pubsub to preserve the previous behavior. Unclear if this is desirable, but can always be changed later. In mod_pep this allows turning off the automatic resending of most recent item.
author Kim Alvefur <zash@zash.se>
date Tue, 19 Oct 2021 18:11:50 +0200
parent 11803:024b44ad5651
child 11855:8890eaa69446
comparison
equal deleted inserted replaced
11853:ae5ac9830add 11854:b605cbd5f13b
118 "subscribers"; 118 "subscribers";
119 "open"; 119 "open";
120 }; 120 };
121 }; 121 };
122 { 122 {
123 type = "list-single";
124 var = "pubsub#send_last_published_item";
125 name = "send_last_published_item";
126 options = { "never"; "on_sub"; "on_sub_and_presence" };
127 };
128 {
123 type = "boolean"; 129 type = "boolean";
124 value = true; 130 value = true;
125 label = "Whether to deliver event notifications"; 131 label = "Whether to deliver event notifications";
126 name = "notify_items"; 132 name = "notify_items";
127 var = "pubsub#deliver_notifications"; 133 var = "pubsub#deliver_notifications";
251 257
252 if service.node_defaults.access_model then 258 if service.node_defaults.access_model then
253 supported_features:add("access-"..service.node_defaults.access_model); 259 supported_features:add("access-"..service.node_defaults.access_model);
254 end 260 end
255 261
262 if service.node_defaults.send_last_published_item ~= "never" then
263 supported_features:add("last-published");
264 end
265
256 if rawget(service.config, "itemstore") and rawget(service.config, "nodestore") then 266 if rawget(service.config, "itemstore") and rawget(service.config, "nodestore") then
257 supported_features:add("persistent-items"); 267 supported_features:add("persistent-items");
258 end 268 end
259 269
260 if true --[[ node_metadata_form[max_items].datatype == "pubsub:integer-or-max" ]] then 270 if true --[[ node_metadata_form[max_items].datatype == "pubsub:integer-or-max" ]] then
528 end 538 end
529 else 539 else
530 reply = pubsub_error_reply(stanza, ret); 540 reply = pubsub_error_reply(stanza, ret);
531 end 541 end
532 origin.send(reply); 542 origin.send(reply);
543 local ok, config = service:get_node_config(node, true);
544 if ok and config.send_last_published_item ~= "never" then
545 local ok, id, item = service:get_last_item(node, jid);
546 if not (ok and id) then return; end
547 service.config.broadcaster("items", node, { [jid] = true }, item);
548 end
533 end 549 end
534 550
535 function handlers.set_unsubscribe(origin, stanza, unsubscribe, service) 551 function handlers.set_unsubscribe(origin, stanza, unsubscribe, service)
536 local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid; 552 local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid;
537 jid = jid_prep(jid); 553 jid = jid_prep(jid);