Software /
code /
verse
Changeset
114:37f5966cff15
verse.plugins.pep: New plugin to add an API for sending and catching PEP events
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 25 Aug 2010 16:27:30 +0100 |
parents | 113:769366a8b238 |
children | 115:9f8cacfca7c7 |
files | plugins/pep.lua squishy |
diffstat | 2 files changed, 46 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/pep.lua Wed Aug 25 16:27:30 2010 +0100 @@ -0,0 +1,45 @@ + +local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; +local xmlns_pubsub_event = xmlns_pubsub.."#event"; + +function verse.plugins.pep(stream) + stream.pep = {}; + + stream:hook("message", function (message) + local event = message:get_child("event", xmlns_pubsub_event); + if not event then return; end + local items = event:get_child("items"); + if not items then return; end + local node = items.attr.node; + for item in items:childtags() do + if item.name == "item" and item.attr.xmlns == xmlns_pubsub_event then + stream:event("pep/"..node, { + from = message.attr.from, + item = item.tags[1], + }); + end + end + end); + + function stream:hook_pep(node, callback, priority) + stream:hook("pep/"..node, callback, priority); + stream:add_disco_feature(node.."+notify"); + end + + function stream:unhook_pep(node, callback) + stream:unhook("pep/"..node, callback); + local handlers = stream.events._handlers["pep/"..node]; + if not(handlers) or #handlers == 0 then + stream:remove_disco_feature(node.."+notify"); + end + end + + function stream:publish_pep(item, node) + local publish = verse.iq({ type = "set" }) + :tag("pubsub", { xmlns = xmlns_pubsub }) + :tag("publish", { node = node or item.attr.xmlns }) + :tag("item") + :add_child(item); + return stream:send_iq(publish); + end +end
--- a/squishy Wed Aug 25 16:18:12 2010 +0100 +++ b/squishy Wed Aug 25 16:27:30 2010 +0100 @@ -32,6 +32,7 @@ Module "verse.plugins.jingle_ft" "plugins/jingle_ft.lua" Module "verse.plugins.jingle_s5b" "plugins/jingle_s5b.lua" Module "verse.plugins.disco" "plugins/disco.lua" +Module "verse.plugins.pep" "plugins/pep.lua" if GetOption "bosh" ~= false then Module "net.httpclient_listener" "net/httpclient_listener.lua"