Comparison

util/pubsub.lua @ 10519:641e3b7a6a39 0.11

util.pubsub: Pass subscribers trough a filter callback
author Kim Alvefur <zash@zash.se>
date Thu, 06 Jun 2019 18:13:46 +0200
parent 10518:9f50489c2033
child 10521:cbb2c3f8bb1d
child 11565:087b275a9aee
comparison
equal deleted inserted replaced
10518:9f50489c2033 10519:641e3b7a6a39
4 local service_mt = {}; 4 local service_mt = {};
5 5
6 local default_config = { 6 local default_config = {
7 itemstore = function (config, _) return cache.new(config["max_items"]) end; 7 itemstore = function (config, _) return cache.new(config["max_items"]) end;
8 broadcaster = function () end; 8 broadcaster = function () end;
9 subscriber_filter = function (subs) return subs end;
9 itemcheck = function () return true; end; 10 itemcheck = function () return true; end;
10 get_affiliation = function () end; 11 get_affiliation = function () end;
11 normalize_jid = function (jid) return jid; end; 12 normalize_jid = function (jid) return jid; end;
12 capabilities = { 13 capabilities = {
13 outcast = { 14 outcast = {
565 self:broadcast("items", node, node_obj.subscribers, item, actor, node_obj); 566 self:broadcast("items", node, node_obj.subscribers, item, actor, node_obj);
566 return true; 567 return true;
567 end 568 end
568 569
569 function service:broadcast(event, node, subscribers, item, actor, node_obj) 570 function service:broadcast(event, node, subscribers, item, actor, node_obj)
571 subscribers = self.config.subscriber_filter(subscribers, node, event);
570 return self.config.broadcaster(event, node, subscribers, item, actor, node_obj, self); 572 return self.config.broadcaster(event, node, subscribers, item, actor, node_obj, self);
571 end 573 end
572 574
573 function service:retract(node, actor, id, retract) --> ok, err 575 function service:retract(node, actor, id, retract) --> ok, err
574 -- Access checking 576 -- Access checking