# HG changeset patch # User Matthew Wild # Date 1290270814 0 # Node ID ab0f0326b2b4f22d52e1234e10d7650cfe8cb04f # Parent a4dc96890729242c3f15c205838c5f7b7a853ac8# Parent 9c9af7a196ed6b40ceb52d16bfe8665175b23332 Merge with Zash diff -r 9c9af7a196ed -r ab0f0326b2b4 plugins/pubsub.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/pubsub.lua Sat Nov 20 16:33:34 2010 +0000 @@ -0,0 +1,46 @@ +local jid_bare = require "util.jid".bare; + +local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; +local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; +local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; + +local pubsub = {}; +local pubsub_mt = { __index = pubsub }; + +function verse.plugins.pubsub(stream) + stream.pubsub = setmetatable({ stream = stream }, pubsub_mt); +end + +function pubsub:subscribe(server, node, jid, callback) + self.stream:send_iq(verse.iq({ to = server, type = "set" }) + :tag("pubsub", { xmlns = xmlns_pubsub }) + :tag("subscribe", { node = node, jid = jid or jid_bare(self.stream.jid) }) + , function (result) + if callback then + if result.attr.type == "result" then + callback(true); + else + callback(false, result:get_error()); + end + end + end + ); +end + +function pubsub:publish(server, node, id, item, callback) + self.stream:send_iq(verse.iq({ to = server, type = "set" }) + :tag("pubsub", { xmlns = xmlns_pubsub }) + :tag("publish", { node = node }) + :tag("item", { id = id }) + :add_child(item) + , function (result) + if callback then + if result.attr.type == "result" then + callback(true); + else + callback(false, result:get_error()); + end + end + end + ); +end diff -r 9c9af7a196ed -r ab0f0326b2b4 squishy --- a/squishy Sat Nov 20 17:27:03 2010 +0100 +++ b/squishy Sat Nov 20 16:33:34 2010 +0000 @@ -28,6 +28,7 @@ Module "verse.plugins.sasl" "plugins/sasl.lua" Module "verse.plugins.bind" "plugins/bind.lua" Module "verse.plugins.legacy" "plugins/legacy.lua" +Module "verse.plugins.pubsub" "plugins/pubsub.lua" Module "verse.plugins.version" "plugins/version.lua" Module "verse.plugins.ping" "plugins/ping.lua" Module "verse.plugins.session" "plugins/session.lua"