Comparison

plugins/pubsub.lua @ 170:cb03e8ae2e30

Merge with Zash
author Matthew Wild <mwild1@gmail.com>
date Wed, 15 Dec 2010 15:03:56 +0000
parent 165:8c67ea868c06
child 193:fa6e1e65cb3c
comparison
equal deleted inserted replaced
169:4bb1e9c91fbe 170:cb03e8ae2e30
7 local pubsub = {}; 7 local pubsub = {};
8 local pubsub_mt = { __index = pubsub }; 8 local pubsub_mt = { __index = pubsub };
9 9
10 function verse.plugins.pubsub(stream) 10 function verse.plugins.pubsub(stream)
11 stream.pubsub = setmetatable({ stream = stream }, pubsub_mt); 11 stream.pubsub = setmetatable({ stream = stream }, pubsub_mt);
12 stream:hook("message", function (message)
13 for pubsub_event in message:matching_tags("event", xmlns_pubsub_event) do
14 local items = pubsub_event:get_child("items");
15 if items then
16 local node = items.attr.node;
17 for item in items:matching_tags("item") do
18 stream:event("pubsub/event", {
19 from = message.attr.from;
20 node = node;
21 item = item;
22 });
23 end
24 end
25 end
26 end);
27 return true;
12 end 28 end
13 29
14 function pubsub:subscribe(server, node, jid, callback) 30 function pubsub:subscribe(server, node, jid, callback)
15 self.stream:send_iq(verse.iq({ to = server, type = "set" }) 31 self.stream:send_iq(verse.iq({ to = server, type = "set" })
16 :tag("pubsub", { xmlns = xmlns_pubsub }) 32 :tag("pubsub", { xmlns = xmlns_pubsub })