Mercurial > prosody-hg
comparison util/pubsub.lua @ 3909:c2dc7f7eed94
util.pubsub: Modify new() to take a config, and add a default config via a metatable
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 21 Dec 2010 03:22:40 +0000 |
| parents | 1f7305784e12 |
| children | 80fe910f912a |
comparison
equal
deleted
inserted
replaced
| 3908:4d8081c35f01 | 3909:c2dc7f7eed94 |
|---|---|
| 1 module("pubsub", package.seeall); | 1 module("pubsub", package.seeall); |
| 2 | 2 |
| 3 local service = {}; | 3 local service = {}; |
| 4 local service_mt = { __index = service }; | 4 local service_mt = { __index = service }; |
| 5 | 5 |
| 6 function new(cb) | 6 local default_config = { |
| 7 return setmetatable({ cb = cb or {}, nodes = {} }, service_mt); | 7 broadcaster = function () end; |
| 8 get_affiliation = function () end; | |
| 9 capabilities = {}; | |
| 10 }; | |
| 11 | |
| 12 function new(config) | |
| 13 config = config or {}; | |
| 14 return setmetatable({ | |
| 15 config = setmetatable(config, { __index = default_config }); | |
| 16 affiliations = {}; | |
| 17 nodes = {}; | |
| 18 }, service_mt); | |
| 8 end | 19 end |
| 9 | 20 |
| 10 function service:add_subscription(node, actor, jid) | 21 function service:add_subscription(node, actor, jid) |
| 11 local node_obj = self.nodes[node]; | 22 local node_obj = self.nodes[node]; |
| 12 if not node_obj then | 23 if not node_obj then |
