Comparison

plugins/pubsub.lua @ 154:a4dc96890729

plugins.pubsub, squishy: New pubsub plugin (basic)
author Matthew Wild <mwild1@gmail.com>
date Tue, 16 Nov 2010 11:49:42 +0000
child 159:88cc513e81c8
comparison
equal deleted inserted replaced
153:f7c705485a2a 154:a4dc96890729
1 local jid_bare = require "util.jid".bare;
2
3 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
4 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
5 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
6
7 local pubsub = {};
8 local pubsub_mt = { __index = pubsub };
9
10 function verse.plugins.pubsub(stream)
11 stream.pubsub = setmetatable({ stream = stream }, pubsub_mt);
12 end
13
14 function pubsub:subscribe(server, node, jid, callback)
15 self.stream:send_iq(verse.iq({ to = server, type = "set" })
16 :tag("pubsub", { xmlns = xmlns_pubsub })
17 :tag("subscribe", { node = node, jid = jid or jid_bare(self.stream.jid) })
18 , function (result)
19 if callback then
20 if result.attr.type == "result" then
21 callback(true);
22 else
23 callback(false, result:get_error());
24 end
25 end
26 end
27 );
28 end
29
30 function pubsub:publish(server, node, id, item, callback)
31 self.stream:send_iq(verse.iq({ to = server, type = "set" })
32 :tag("pubsub", { xmlns = xmlns_pubsub })
33 :tag("publish", { node = node })
34 :tag("item", { id = id })
35 :add_child(item)
36 , function (result)
37 if callback then
38 if result.attr.type == "result" then
39 callback(true);
40 else
41 callback(false, result:get_error());
42 end
43 end
44 end
45 );
46 end