Software /
code /
prosody
Comparison
util/pubsub.lua @ 10521:cbb2c3f8bb1d
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 23 Dec 2019 20:57:10 +0100 |
parent | 10356:0a2d7efca039 |
parent | 10519:641e3b7a6a39 |
child | 10537:c5558138ce33 |
comparison
equal
deleted
inserted
replaced
10517:6e1163fa2cd2 | 10521:cbb2c3f8bb1d |
---|---|
5 local service_mt = {}; | 5 local service_mt = {}; |
6 | 6 |
7 local default_config = { | 7 local default_config = { |
8 itemstore = function (config, _) return cache.new(config["max_items"]) end; | 8 itemstore = function (config, _) return cache.new(config["max_items"]) end; |
9 broadcaster = function () end; | 9 broadcaster = function () end; |
10 subscriber_filter = function (subs) return subs end; | |
10 itemcheck = function () return true; end; | 11 itemcheck = function () return true; end; |
11 get_affiliation = function () end; | 12 get_affiliation = function () end; |
12 normalize_jid = function (jid) return jid; end; | 13 normalize_jid = function (jid) return jid; end; |
13 capabilities = { | 14 capabilities = { |
14 outcast = { | 15 outcast = { |
498 return ok, err; | 499 return ok, err; |
499 end | 500 end |
500 end | 501 end |
501 | 502 |
502 self.events.fire_event("node-deleted", { service = self, node = node, actor = actor }); | 503 self.events.fire_event("node-deleted", { service = self, node = node, actor = actor }); |
503 self.config.broadcaster("delete", node, node_obj.subscribers, nil, actor, node_obj, self); | 504 self:broadcast("delete", node, node_obj.subscribers, nil, actor, node_obj); |
504 return true; | 505 return true; |
505 end | 506 end |
506 | 507 |
507 -- Used to check that the config of a node is as expected (i.e. 'publish-options') | 508 -- Used to check that the config of a node is as expected (i.e. 'publish-options') |
508 local function check_preconditions(node_config, required_config) | 509 local function check_preconditions(node_config, required_config) |
566 end | 567 end |
567 if type(ok) == "string" then id = ok; end | 568 if type(ok) == "string" then id = ok; end |
568 local event_data = { service = self, node = node, actor = actor, id = id, item = item }; | 569 local event_data = { service = self, node = node, actor = actor, id = id, item = item }; |
569 self.events.fire_event("item-published/"..node, event_data); | 570 self.events.fire_event("item-published/"..node, event_data); |
570 self.events.fire_event("item-published", event_data); | 571 self.events.fire_event("item-published", event_data); |
571 self.config.broadcaster("items", node, node_obj.subscribers, item, actor, node_obj, self); | 572 self:broadcast("items", node, node_obj.subscribers, item, actor, node_obj); |
572 return true; | 573 return true; |
574 end | |
575 | |
576 function service:broadcast(event, node, subscribers, item, actor, node_obj) | |
577 subscribers = self.config.subscriber_filter(subscribers, node, event); | |
578 return self.config.broadcaster(event, node, subscribers, item, actor, node_obj, self); | |
573 end | 579 end |
574 | 580 |
575 function service:retract(node, actor, id, retract) --> ok, err | 581 function service:retract(node, actor, id, retract) --> ok, err |
576 -- Access checking | 582 -- Access checking |
577 if not self:may(node, actor, "retract") then | 583 if not self:may(node, actor, "retract") then |
586 if not ok then | 592 if not ok then |
587 return nil, "internal-server-error"; | 593 return nil, "internal-server-error"; |
588 end | 594 end |
589 self.events.fire_event("item-retracted", { service = self, node = node, actor = actor, id = id }); | 595 self.events.fire_event("item-retracted", { service = self, node = node, actor = actor, id = id }); |
590 if retract then | 596 if retract then |
591 self.config.broadcaster("retract", node, node_obj.subscribers, retract, actor, node_obj, self); | 597 self:broadcast("retract", node, node_obj.subscribers, retract, actor, node_obj); |
592 end | 598 end |
593 return true | 599 return true |
594 end | 600 end |
595 | 601 |
596 function service:purge(node, actor, notify) --> ok, err | 602 function service:purge(node, actor, notify) --> ok, err |
608 else | 614 else |
609 self.data[node] = self.config.itemstore(self.nodes[node].config, node); | 615 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
610 end | 616 end |
611 self.events.fire_event("node-purged", { service = self, node = node, actor = actor }); | 617 self.events.fire_event("node-purged", { service = self, node = node, actor = actor }); |
612 if notify then | 618 if notify then |
613 self.config.broadcaster("purge", node, node_obj.subscribers, nil, actor, node_obj, self); | 619 self:broadcast("purge", node, node_obj.subscribers, nil, actor, node_obj); |
614 end | 620 end |
615 return true | 621 return true |
616 end | 622 end |
617 | 623 |
618 function service:get_items(node, actor, ids) --> (true, { id, [id] = node }) or (false, err) | 624 function service:get_items(node, actor, ids) --> (true, { id, [id] = node }) or (false, err) |