plugins/pubsub.lua

changeset 159
88cc513e81c8
parent 154
a4dc96890729
child 165
8c67ea868c06
equal deleted inserted replaced
158:068176069dfa 159:88cc513e81c8
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);
12 end 27 end
13 28
14 function pubsub:subscribe(server, node, jid, callback) 29 function pubsub:subscribe(server, node, jid, callback)
15 self.stream:send_iq(verse.iq({ to = server, type = "set" }) 30 self.stream:send_iq(verse.iq({ to = server, type = "set" })
16 :tag("pubsub", { xmlns = xmlns_pubsub }) 31 :tag("pubsub", { xmlns = xmlns_pubsub })

mercurial