Software /
code /
prosody
Comparison
util/pubsub.lua @ 9031:d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 13 Jul 2018 04:41:59 +0200 |
parent | 8956:82f92af4b0f3 |
child | 9075:46d4322f7eed |
comparison
equal
deleted
inserted
replaced
9030:7d0b7e086c6a | 9031:d1a4b1b78695 |
---|---|
456 end | 456 end |
457 -- | 457 -- |
458 return true, self.nodes; | 458 return true, self.nodes; |
459 end | 459 end |
460 | 460 |
461 local function flatten_subscriptions(ret, serv, subs, node, node_obj) | |
462 for subscribed_jid, subscribed_nodes in pairs(subs) do | |
463 if node then -- Return only subscriptions to this node | |
464 if subscribed_nodes[node] then | |
465 ret[#ret+1] = { | |
466 node = node; | |
467 jid = subscribed_jid; | |
468 subscription = node_obj.subscribers[subscribed_jid]; | |
469 }; | |
470 end | |
471 else -- Return subscriptions to all nodes | |
472 local nodes = serv.nodes; | |
473 for subscribed_node in pairs(subscribed_nodes) do | |
474 ret[#ret+1] = { | |
475 node = subscribed_node; | |
476 jid = subscribed_jid; | |
477 subscription = nodes[subscribed_node].subscribers[subscribed_jid]; | |
478 }; | |
479 end | |
480 end | |
481 end | |
482 end | |
483 | |
461 function service:get_subscriptions(node, actor, jid) | 484 function service:get_subscriptions(node, actor, jid) |
462 -- Access checking | 485 -- Access checking |
463 local cap; | 486 local cap; |
464 if actor == true or jid == actor or self:jids_equal(actor, jid) then | 487 if actor == true or jid == actor or self:jids_equal(actor, jid) then |
465 cap = "get_subscriptions"; | 488 cap = "get_subscriptions"; |
475 node_obj = self.nodes[node]; | 498 node_obj = self.nodes[node]; |
476 if not node_obj then | 499 if not node_obj then |
477 return false, "item-not-found"; | 500 return false, "item-not-found"; |
478 end | 501 end |
479 end | 502 end |
503 local ret = {}; | |
504 if jid == nil then | |
505 for _, subs in pairs(self.subscriptions) do | |
506 flatten_subscriptions(ret, self, subs, node, node_obj) | |
507 end | |
508 return true, ret; | |
509 end | |
480 local normal_jid = self.config.normalize_jid(jid); | 510 local normal_jid = self.config.normalize_jid(jid); |
481 local subs = self.subscriptions[normal_jid]; | 511 local subs = self.subscriptions[normal_jid]; |
482 -- We return the subscription object from the node to save | 512 -- We return the subscription object from the node to save |
483 -- a get_subscription() call for each node. | 513 -- a get_subscription() call for each node. |
484 local ret = {}; | |
485 if subs then | 514 if subs then |
486 for subscribed_jid, subscribed_nodes in pairs(subs) do | 515 flatten_subscriptions(ret, self, subs, node, node_obj) |
487 if node then -- Return only subscriptions to this node | |
488 if subscribed_nodes[node] then | |
489 ret[#ret+1] = { | |
490 node = node; | |
491 jid = subscribed_jid; | |
492 subscription = node_obj.subscribers[subscribed_jid]; | |
493 }; | |
494 end | |
495 else -- Return subscriptions to all nodes | |
496 local nodes = self.nodes; | |
497 for subscribed_node in pairs(subscribed_nodes) do | |
498 ret[#ret+1] = { | |
499 node = subscribed_node; | |
500 jid = subscribed_jid; | |
501 subscription = nodes[subscribed_node].subscribers[subscribed_jid]; | |
502 }; | |
503 end | |
504 end | |
505 end | |
506 end | 516 end |
507 return true, ret; | 517 return true, ret; |
508 end | 518 end |
509 | 519 |
510 -- Access models only affect 'none' affiliation caps, service/default access level... | 520 -- Access models only affect 'none' affiliation caps, service/default access level... |