Comparison

util/pubsub.lua @ 9816:7f84d7f77a00 0.11

util.pubsub: Add support for requesting multiple specific items (needed for #1305)
author Kim Alvefur <zash@zash.se>
date Mon, 28 Jan 2019 01:41:01 +0100
parent 9742:18eca6afb367
child 9840:ec353524b739
comparison
equal deleted inserted replaced
9814:5eb4ef537e98 9816:7f84d7f77a00
598 self.config.broadcaster("purge", node, node_obj.subscribers, nil, actor, node_obj, self); 598 self.config.broadcaster("purge", node, node_obj.subscribers, nil, actor, node_obj, self);
599 end 599 end
600 return true 600 return true
601 end 601 end
602 602
603 function service:get_items(node, actor, id) --> (true, { id, [id] = node }) or (false, err) 603 function service:get_items(node, actor, ids) --> (true, { id, [id] = node }) or (false, err)
604 -- Access checking 604 -- Access checking
605 if not self:may(node, actor, "get_items") then 605 if not self:may(node, actor, "get_items") then
606 return false, "forbidden"; 606 return false, "forbidden";
607 end 607 end
608 -- 608 --
609 local node_obj = self.nodes[node]; 609 local node_obj = self.nodes[node];
610 if not node_obj then 610 if not node_obj then
611 return false, "item-not-found"; 611 return false, "item-not-found";
612 end 612 end
613 if id then -- Restrict results to a single specific item 613 if type(ids) == "string" then -- COMPAT see #1305
614 local with_id = self.data[node]:get(id); 614 ids = { ids };
615 if not with_id then 615 end
616 return true, { }; 616 local data = {};
617 end 617 if ids then
618 return true, { id, [id] = with_id }; 618 for _, key in ipairs(ids) do
619 local value = self.data[node]:get(key);
620 if value then
621 data[#data+1] = key;
622 data[key] = value;
623 end
624 end
619 else 625 else
620 local data = {}
621 for key, value in self.data[node]:items() do 626 for key, value in self.data[node]:items() do
622 data[#data+1] = key; 627 data[#data+1] = key;
623 data[key] = value; 628 data[key] = value;
624 end 629 end
625 return true, data; 630 end
626 end 631 return true, data;
627 end 632 end
628 633
629 function service:get_last_item(node, actor) --> (true, id, node) or (false, err) 634 function service:get_last_item(node, actor) --> (true, id, node) or (false, err)
630 -- Access checking 635 -- Access checking
631 if not self:may(node, actor, "get_items") then 636 if not self:may(node, actor, "get_items") then