Mercurial > prosody-hg
comparison util/pubsub.lua @ 3641:3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Thu, 25 Nov 2010 21:47:12 +0100 |
| parents | 444f965baed8 |
| children | b24db47995ac |
comparison
equal
deleted
inserted
replaced
| 3640:4bc88bb748d1 | 3641:3603aeb325de |
|---|---|
| 29 end | 29 end |
| 30 | 30 |
| 31 function service:publish(node, actor, id, item) | 31 function service:publish(node, actor, id, item) |
| 32 local node_obj = self.nodes[node]; | 32 local node_obj = self.nodes[node]; |
| 33 if not node_obj then | 33 if not node_obj then |
| 34 node_obj = { name = node, subscribers = {}, config = {} }; | 34 node_obj = { name = node, subscribers = {}, config = {}, data = {} }; |
| 35 self.nodes[node] = node_obj; | 35 self.nodes[node] = node_obj; |
| 36 end | 36 end |
| 37 node_obj.data = item; | 37 node_obj.data[id] = item; |
| 38 self.cb.broadcaster(node, node_obj.subscribers, item); | 38 self.cb.broadcaster(node, node_obj.subscribers, item); |
| 39 return true; | 39 return true; |
| 40 end | 40 end |
| 41 | 41 |
| 42 function service:get(node, actor, id) | |
| 43 local node_obj = self.nodes[node]; | |
| 44 if node_obj then | |
| 45 if id then | |
| 46 return { node_obj.data[id] }; | |
| 47 else | |
| 48 return node_obj.data; | |
| 49 end | |
| 50 end | |
| 51 end | |
| 52 | |
| 42 return _M; | 53 return _M; |
