Software /
code /
verse
Comparison
plugins/pep.lua @ 216:3aac084855e6
plugins.pep: Reuse the pubsub plugin.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 08 Sep 2011 18:03:07 +0200 |
parent | 164:d862093d9f91 |
child | 232:5b49de3aa0f3 |
comparison
equal
deleted
inserted
replaced
215:f86e0b0a0be3 | 216:3aac084855e6 |
---|---|
1 | 1 |
2 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; | 2 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
3 local xmlns_pubsub_event = xmlns_pubsub.."#event"; | 3 local xmlns_pubsub_event = xmlns_pubsub.."#event"; |
4 | 4 |
5 function verse.plugins.pep(stream) | 5 function verse.plugins.pep(stream) |
6 stream:add_plugin("pubsub"); | |
6 stream.pep = {}; | 7 stream.pep = {}; |
7 | 8 |
8 stream:hook("message", function (message) | 9 stream:hook("pubsub/event", function(event) |
9 local event = message:get_child("event", xmlns_pubsub_event); | 10 return stream:event("pep/"..event.node, { from = event.from, item = event.item[1] } ); |
10 if not event then return; end | |
11 local items = event:get_child("items"); | |
12 if not items then return; end | |
13 local node = items.attr.node; | |
14 for item in items:childtags() do | |
15 if item.name == "item" and item.attr.xmlns == xmlns_pubsub_event then | |
16 stream:event("pep/"..node, { | |
17 from = message.attr.from, | |
18 item = item.tags[1], | |
19 }); | |
20 end | |
21 end | |
22 end); | 11 end); |
23 | 12 |
24 function stream:hook_pep(node, callback, priority) | 13 function stream:hook_pep(node, callback, priority) |
25 local handlers = stream.events._handlers["pep/"..node]; | 14 local handlers = stream.events._handlers["pep/"..node]; |
26 if not(handlers) or #handlers == 0 then | 15 if not(handlers) or #handlers == 0 then |
36 stream:remove_disco_feature(node.."+notify"); | 25 stream:remove_disco_feature(node.."+notify"); |
37 end | 26 end |
38 end | 27 end |
39 | 28 |
40 function stream:publish_pep(item, node) | 29 function stream:publish_pep(item, node) |
41 local publish = verse.iq({ type = "set" }) | 30 return stream.pubsub:publish(nil, node or item.attr.xmlns, nil, item) |
42 :tag("pubsub", { xmlns = xmlns_pubsub }) | |
43 :tag("publish", { node = node or item.attr.xmlns }) | |
44 :tag("item") | |
45 :add_child(item); | |
46 return stream:send_iq(publish); | |
47 end | 31 end |
48 end | 32 end |