aboutsummaryrefslogtreecommitdiffstats
path: root/util/pubsub.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-11-13 03:16:58 +0000
committerMatthew Wild <mwild1@gmail.com>2010-11-13 03:16:58 +0000
commit3ffba43bf566c8655196df75f5ce1cc127e30af8 (patch)
treedf837015096d434697bb1f97e54f3bc20b10c921 /util/pubsub.lua
parent0dbe39b4207a4b8d030703a27394f8bf044f785f (diff)
downloadprosody-3ffba43bf566c8655196df75f5ce1cc127e30af8.tar.gz
prosody-3ffba43bf566c8655196df75f5ce1cc127e30af8.zip
mod_pubsub: It's aliiiive!
Diffstat (limited to 'util/pubsub.lua')
-rw-r--r--util/pubsub.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/util/pubsub.lua b/util/pubsub.lua
new file mode 100644
index 00000000..34859fdb
--- /dev/null
+++ b/util/pubsub.lua
@@ -0,0 +1,35 @@
+module("pubsub", package.seeall);
+
+local service = {};
+local service_mt = { __index = service };
+
+function new(cb)
+ return setmetatable({ cb = cb or {}, nodes = {} }, service_mt);
+end
+
+function service:add_subscription(node, actor, jid)
+ local node_obj = self.nodes[node];
+ if not node_obj then
+ return false, "item-not-found";
+ end
+ node_obj.subscribers[jid] = true;
+ return true;
+end
+
+function service:remove_subscription(node, actor, jid)
+ self.nodes[node].subscribers[jid] = nil;
+ return true;
+end
+
+function service:publish(node, actor, id, item)
+ local node_obj = self.nodes[node];
+ if not node_obj then
+ node_obj = { name = node, subscribers = {}, config = {} };
+ self.nodes[node] = node_obj;
+ end
+ node_obj.data = item;
+ self.cb.broadcaster(node, node_obj.subscribers, item);
+ return true;
+end
+
+return _M;