Annotate

plugins/pubsub.lua @ 479:2bb12fb6fcbd

squishy: Updates for Prosody trunk (@ e77c607e8da8)
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 Mar 2023 12:30:25 +0000
parent 468:fae5ae0ddb84
child 490:6b2f31da9610
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 248
diff changeset
1 local verse = require "verse";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 248
diff changeset
2
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
3 local t_insert = table.insert;
154
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
6 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
154
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
395
e86144a4eaa1 plugins: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 348
diff changeset
8 -- local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
154
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local pubsub = {};
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local pubsub_mt = { __index = pubsub };
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 function verse.plugins.pubsub(stream)
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 stream.pubsub = setmetatable({ stream = stream }, pubsub_mt);
159
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
15 stream:hook("message", function (message)
283
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
16 local m_from = message.attr.from;
193
fa6e1e65cb3c plugins.pubsub: Fix to use :childtags() for iterating through items in a pubsub notification (:matching_tags() was removed from Prosody)
Matthew Wild <mwild1@gmail.com>
parents: 165
diff changeset
17 for pubsub_event in message:childtags("event", xmlns_pubsub_event) do
159
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
18 local items = pubsub_event:get_child("items");
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
19 if items then
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
20 local node = items.attr.node;
193
fa6e1e65cb3c plugins.pubsub: Fix to use :childtags() for iterating through items in a pubsub notification (:matching_tags() was removed from Prosody)
Matthew Wild <mwild1@gmail.com>
parents: 165
diff changeset
21 for item in items:childtags("item") do
159
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
22 stream:event("pubsub/event", {
283
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
23 from = m_from;
159
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
24 node = node;
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
25 item = item;
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
26 });
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
27 end
468
fae5ae0ddb84 pubsub: Fire event on item retraction notifications
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
28 for retract in items:childtags("retract") do
fae5ae0ddb84 pubsub: Fire event on item retraction notifications
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
29 stream:event("pubsub/retraction", {
fae5ae0ddb84 pubsub: Fire event on item retraction notifications
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
30 from = m_from;
fae5ae0ddb84 pubsub: Fire event on item retraction notifications
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
31 node = node;
fae5ae0ddb84 pubsub: Fire event on item retraction notifications
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
32 item = retract;
fae5ae0ddb84 pubsub: Fire event on item retraction notifications
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
33 });
fae5ae0ddb84 pubsub: Fire event on item retraction notifications
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
34 end
159
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
35 end
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
36 end
88cc513e81c8 plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
Matthew Wild <mwild1@gmail.com>
parents: 154
diff changeset
37 end);
165
8c67ea868c06 plugins.pubsub: Return true to indicate success loading
Matthew Wild <mwild1@gmail.com>
parents: 159
diff changeset
38 return true;
154
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 end
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40
248
c4b55b0dc6ba plugins.pubsub: Make the old functions wrap the new.
Kim Alvefur <zash@zash.se>
parents: 222
diff changeset
41 -- COMPAT
221
efb4f60ba36e plugins.pubsub: implement node creation
Kim Alvefur <zash@zash.se>
parents: 193
diff changeset
42 function pubsub:create(server, node, callback)
265
2a2326a8f9e8 plugins.pubsub: Fix to use correct method in backwards-compatibility code
Matthew Wild <mwild1@gmail.com>
parents: 264
diff changeset
43 return self:service(server):node(node):create(nil, callback);
221
efb4f60ba36e plugins.pubsub: implement node creation
Kim Alvefur <zash@zash.se>
parents: 193
diff changeset
44 end
efb4f60ba36e plugins.pubsub: implement node creation
Kim Alvefur <zash@zash.se>
parents: 193
diff changeset
45
154
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 function pubsub:subscribe(server, node, jid, callback)
265
2a2326a8f9e8 plugins.pubsub: Fix to use correct method in backwards-compatibility code
Matthew Wild <mwild1@gmail.com>
parents: 264
diff changeset
47 return self:service(server):node(node):subscribe(jid, nil, callback);
154
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 function pubsub:publish(server, node, id, item, callback)
265
2a2326a8f9e8 plugins.pubsub: Fix to use correct method in backwards-compatibility code
Matthew Wild <mwild1@gmail.com>
parents: 264
diff changeset
51 return self:service(server):node(node):publish(id, nil, item, callback);
154
a4dc96890729 plugins.pubsub, squishy: New pubsub plugin (basic)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
53
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
54 --------------------------------------------------------------------------
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
55 ---------------------New and improved PubSub interface--------------------
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
56 --------------------------------------------------------------------------
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
57
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
58 local pubsub_service = {};
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
59 local pubsub_service_mt = { __index = pubsub_service };
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
60
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
61 -- TODO should the property be named 'jid' instead?
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
62 function pubsub:service(service)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
63 return setmetatable({ stream = self.stream, service = service }, pubsub_service_mt)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
64 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
65
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
66 -- Helper function for iq+pubsub tags
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
67
437
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
68 local function pubsub_iq(iq_type, to, ns, op, node, jid, item_id, op_attr_extra)
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
69 local st = verse.iq{ type = iq_type or "get", to = to }
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
70 :tag("pubsub", { xmlns = ns or xmlns_pubsub }) -- ns would be ..#owner
437
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
71 local op_attr = { node = node, jid = jid };
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
72 if op_attr_extra then
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
73 for k, v in pairs(op_attr_extra) do
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
74 op_attr[k] = v;
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
75 end
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
76 end
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
77 if op then st:tag(op, op_attr); end
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
78 if item_id then
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
79 st:tag("item", { id = item_id ~= true and item_id or nil });
2762abec4c63 pubsub: Allow setting additional attributes in pubsub action elements
Matthew Wild <mwild1@gmail.com>
parents: 395
diff changeset
80 end
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
81 return st;
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
82 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
83
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
84 -- http://xmpp.org/extensions/xep-0060.html#entity-subscriptions
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
85 function pubsub_service:subscriptions(callback)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
86 self.stream:send_iq(pubsub_iq(nil, self.service, nil, "subscriptions")
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
87 , callback and function (result)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
88 if result.attr.type == "result" then
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
89 local ps = result:get_child("pubsub", xmlns_pubsub);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
90 local subs = ps and ps:get_child("subscriptions");
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
91 local nodes = {};
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
92 if subs then
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
93 for sub in subs:childtags("subscription") do
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
94 local node = self:node(sub.attr.node)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
95 node.subscription = sub;
337
8dce8240a77c plugins.pubsub: Collect the subscribed jid
Kim Alvefur <zash@zash.se>
parents: 333
diff changeset
96 node.subscribed_jid = sub.attr.jid;
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
97 t_insert(nodes, node);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
98 -- FIXME Good enough?
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
99 -- Or how about:
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
100 -- nodes[node] = sub;
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
101 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
102 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
103 callback(nodes);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
104 else
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
105 callback(false, result:get_error());
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
106 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
107 end or nil);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
108 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
109
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
110 -- http://xmpp.org/extensions/xep-0060.html#entity-affiliations
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
111 function pubsub_service:affiliations(callback)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
112 self.stream:send_iq(pubsub_iq(nil, self.service, nil, "affiliations")
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
113 , callback and function (result)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
114 if result.attr.type == "result" then
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
115 local ps = result:get_child("pubsub", xmlns_pubsub);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
116 local affils = ps and ps:get_child("affiliations") or {};
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
117 local nodes = {};
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
118 if affils then
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
119 for affil in affils:childtags("affiliation") do
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
120 local node = self:node(affil.attr.node)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
121 node.affiliation = affil;
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
122 t_insert(nodes, node);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
123 -- nodes[node] = affil;
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
124 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
125 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
126 callback(nodes);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
127 else
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
128 callback(false, result:get_error());
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
129 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
130 end or nil);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
131 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
132
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
133 function pubsub_service:nodes(callback)
346
f7854dd16ed3 plugins.pubsub: Implement node discovery
Kim Alvefur <zash@zash.se>
parents: 338
diff changeset
134 self.stream:disco_items(self.service, nil, function(items, ...)
f7854dd16ed3 plugins.pubsub: Implement node discovery
Kim Alvefur <zash@zash.se>
parents: 338
diff changeset
135 if items then
f7854dd16ed3 plugins.pubsub: Implement node discovery
Kim Alvefur <zash@zash.se>
parents: 338
diff changeset
136 for i=1,#items do
f7854dd16ed3 plugins.pubsub: Implement node discovery
Kim Alvefur <zash@zash.se>
parents: 338
diff changeset
137 items[i] = self:node(items[i].node);
f7854dd16ed3 plugins.pubsub: Implement node discovery
Kim Alvefur <zash@zash.se>
parents: 338
diff changeset
138 end
f7854dd16ed3 plugins.pubsub: Implement node discovery
Kim Alvefur <zash@zash.se>
parents: 338
diff changeset
139 end
f7854dd16ed3 plugins.pubsub: Implement node discovery
Kim Alvefur <zash@zash.se>
parents: 338
diff changeset
140 callback(items, ...)
f7854dd16ed3 plugins.pubsub: Implement node discovery
Kim Alvefur <zash@zash.se>
parents: 338
diff changeset
141 end);
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
142 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
143
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
144 local pubsub_node = {};
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
145 local pubsub_node_mt = { __index = pubsub_node };
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
146
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
147 function pubsub_service:node(node)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
148 return setmetatable({ stream = self.stream, service = self.service, node = node }, pubsub_node_mt)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
149 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
150
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
151 function pubsub_mt:__call(service, node)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
152 local s = self:service(service);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
153 return node and s:node(node) or s;
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
154 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
155
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
156 function pubsub_node:hook(callback, prio)
347
48cc6cad9bd6 plugins.pubsub: Keep track of wrapped callbacks
Kim Alvefur <zash@zash.se>
parents: 346
diff changeset
157 self._hooks = self._hooks or setmetatable({}, { __mode = 'kv' });
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
158 local function hook(event)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
159 -- FIXME service == nil would mean anyone,
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
160 -- publishing would be go to your bare jid.
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
161 -- So if you're only interestied in your own
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
162 -- events, hook your own bare jid.
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
163 if (not event.service or event.from == self.service) and event.node == self.node then
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
164 return callback(event)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
165 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
166 end
347
48cc6cad9bd6 plugins.pubsub: Keep track of wrapped callbacks
Kim Alvefur <zash@zash.se>
parents: 346
diff changeset
167 self._hooks[callback] = hook;
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
168 self.stream:hook("pubsub/event", hook, prio);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
169 return hook;
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
170 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
171
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
172 function pubsub_node:unhook(callback)
347
48cc6cad9bd6 plugins.pubsub: Keep track of wrapped callbacks
Kim Alvefur <zash@zash.se>
parents: 346
diff changeset
173 if callback then
48cc6cad9bd6 plugins.pubsub: Keep track of wrapped callbacks
Kim Alvefur <zash@zash.se>
parents: 346
diff changeset
174 local hook = self._hooks[callback];
48cc6cad9bd6 plugins.pubsub: Keep track of wrapped callbacks
Kim Alvefur <zash@zash.se>
parents: 346
diff changeset
175 self.stream:unhook("pubsub/event", hook);
48cc6cad9bd6 plugins.pubsub: Keep track of wrapped callbacks
Kim Alvefur <zash@zash.se>
parents: 346
diff changeset
176 elseif self._hooks then
48cc6cad9bd6 plugins.pubsub: Keep track of wrapped callbacks
Kim Alvefur <zash@zash.se>
parents: 346
diff changeset
177 for hook in pairs(self._hooks) do
48cc6cad9bd6 plugins.pubsub: Keep track of wrapped callbacks
Kim Alvefur <zash@zash.se>
parents: 346
diff changeset
178 self.stream:unhook("pubsub/event", hook);
48cc6cad9bd6 plugins.pubsub: Keep track of wrapped callbacks
Kim Alvefur <zash@zash.se>
parents: 346
diff changeset
179 end
48cc6cad9bd6 plugins.pubsub: Keep track of wrapped callbacks
Kim Alvefur <zash@zash.se>
parents: 346
diff changeset
180 end
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
181 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
182
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
183 function pubsub_node:create(config, callback)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
184 if config ~= nil then
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
185 error("Not implemented yet.");
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
186 else
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
187 self.stream:send_iq(pubsub_iq("set", self.service, nil, "create", self.node), callback);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
188 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
189 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
190
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
191 -- <configure/> and <default/> rolled into one
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
192 function pubsub_node:configure(config, callback)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
193 if config ~= nil then
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
194 error("Not implemented yet.");
283
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
195 --[[
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
196 if config == true then
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
197 self.stream:send_iq(pubsub_iq("get", self.service, nil, "configure", self.node)
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
198 , function(reply)
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
199 local form = reply:get_child("pubsub"):get_child("configure"):get_cild("x");
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
200 local config = callback(require"util.dataforms".something(form))
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
201 self.stream:send_iq(pubsub_iq("set", config, ...))
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
202 end);
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
203 end
39ce7535887c plugins.pubsub: Add a local variable to save some table lookups
Kim Alvefur <zash@zash.se>
parents: 272
diff changeset
204 --]]
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
205 -- fetch form and pass it to the callback
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
206 -- which would process it and pass it back
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
207 -- and then we submit it
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
208 -- elseif type(config) == "table" then
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
209 -- it's a form or stanza that we submit
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
210 -- end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
211 -- this would be done for everything that needs a config
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
212 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
213 self.stream:send_iq(pubsub_iq("set", self.service, nil, config == nil and "default" or "configure", self.node), callback);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
214 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
215
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
216 function pubsub_node:publish(id, options, node, callback)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
217 if options ~= nil then
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
218 error("Node configuration is not implemented yet.");
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
219 end
263
598e9f93de78 plugins.pubsub: Fix missing <item/> when publishing.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
220 self.stream:send_iq(pubsub_iq("set", self.service, nil, "publish", self.node, nil, id or true)
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
221 :add_child(node)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
222 , callback);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
223 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
224
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
225 function pubsub_node:subscribe(jid, options, callback)
332
6ecf44918156 plugins.pubsub: Explicitly subscribe with our current full jid as default
Kim Alvefur <zash@zash.se>
parents: 283
diff changeset
226 jid = jid or self.stream.jid;
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
227 if options ~= nil then
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
228 error("Subscription configuration is not implemented yet.");
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
229 end
395
e86144a4eaa1 plugins: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 348
diff changeset
230 self.stream:send_iq(pubsub_iq("set", self.service, nil, "subscribe", self.node, jid)
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
231 , callback);
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
232 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
233
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
234 function pubsub_node:subscription(callback)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
235 error("Not implemented yet.");
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
236 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
237
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
238 function pubsub_node:affiliation(callback)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
239 error("Not implemented yet.");
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
240 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
241
272
e1833e9bd25b plugins.pubsub: Implement unsubscribe.
Kim Alvefur <zash@zash.se>
parents: 265
diff changeset
242 function pubsub_node:unsubscribe(jid, callback)
338
957704bbe9a1 plugins.pubsub: If no jid given to unsubscribe with, default to what was subscribed to (if given) or the bound jid
Kim Alvefur <zash@zash.se>
parents: 337
diff changeset
243 jid = jid or self.subscribed_jid or self.stream.jid;
272
e1833e9bd25b plugins.pubsub: Implement unsubscribe.
Kim Alvefur <zash@zash.se>
parents: 265
diff changeset
244 self.stream:send_iq(pubsub_iq("set", self.service, nil, "unsubscribe", self.node, jid)
e1833e9bd25b plugins.pubsub: Implement unsubscribe.
Kim Alvefur <zash@zash.se>
parents: 265
diff changeset
245 , callback);
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
246 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
247
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
248 function pubsub_node:configure_subscription(options, callback)
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
249 error("Not implemented yet.");
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
250 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
251
348
34b878d58948 plugins.pubsub: Implement fetching of items
Kim Alvefur <zash@zash.se>
parents: 347
diff changeset
252 function pubsub_node:items(full, callback)
34b878d58948 plugins.pubsub: Implement fetching of items
Kim Alvefur <zash@zash.se>
parents: 347
diff changeset
253 if full then
468
fae5ae0ddb84 pubsub: Fire event on item retraction notifications
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
254 return self:item(nil, callback);
348
34b878d58948 plugins.pubsub: Implement fetching of items
Kim Alvefur <zash@zash.se>
parents: 347
diff changeset
255 else
34b878d58948 plugins.pubsub: Implement fetching of items
Kim Alvefur <zash@zash.se>
parents: 347
diff changeset
256 self.stream:disco_items(self.service, self.node, callback);
34b878d58948 plugins.pubsub: Implement fetching of items
Kim Alvefur <zash@zash.se>
parents: 347
diff changeset
257 end
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
258 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
259
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
260 function pubsub_node:item(id, callback)
348
34b878d58948 plugins.pubsub: Implement fetching of items
Kim Alvefur <zash@zash.se>
parents: 347
diff changeset
261 self.stream:send_iq(pubsub_iq("get", self.service, nil, "items", self.node, nil, id)
34b878d58948 plugins.pubsub: Implement fetching of items
Kim Alvefur <zash@zash.se>
parents: 347
diff changeset
262 , callback);
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
263 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
264
438
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
265 function pubsub_node:retract(id, notify, callback)
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
266 if type(notify) == "function" then -- COMPAT w/ older versions before 'notify' was added
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
267 notify, callback = false, notify;
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
268 end
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
269 self.stream:send_iq(
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
270 pubsub_iq(
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
271 "set",
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
272 self.service,
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
273 nil,
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
274 "retract",
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
275 self.node,
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
276 nil,
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
277 id,
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
278 { notify = notify and "1" or nil }
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
279 ),
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
280 callback
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
281 );
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
282 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
283
333
36e9d5a2ae79 plugins.pubsub: Implement retract, purge and delete operations
Kim Alvefur <zash@zash.se>
parents: 332
diff changeset
284 function pubsub_node:purge(notify, callback)
438
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
285 self.stream:send_iq(
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
286 pubsub_iq(
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
287 "set",
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
288 self.service,
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
289 xmlns_pubsub_owner,
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
290 "purge",
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
291 self.node,
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
292 nil,
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
293 nil,
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
294 { notify = notify and "1" or nil }
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
295 ),
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
296 callback
98dc1750584d pubsub: Support for 'notify' in retract and purge operations
Matthew Wild <mwild1@gmail.com>
parents: 437
diff changeset
297 );
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
298 end
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
299
333
36e9d5a2ae79 plugins.pubsub: Implement retract, purge and delete operations
Kim Alvefur <zash@zash.se>
parents: 332
diff changeset
300 function pubsub_node:delete(redirect_uri, callback)
36e9d5a2ae79 plugins.pubsub: Implement retract, purge and delete operations
Kim Alvefur <zash@zash.se>
parents: 332
diff changeset
301 assert(not redirect_uri, "Not implemented yet.");
36e9d5a2ae79 plugins.pubsub: Implement retract, purge and delete operations
Kim Alvefur <zash@zash.se>
parents: 332
diff changeset
302 self.stream:send_iq(pubsub_iq("set", self.service, xmlns_pubsub_owner, "delete", self.node)
36e9d5a2ae79 plugins.pubsub: Implement retract, purge and delete operations
Kim Alvefur <zash@zash.se>
parents: 332
diff changeset
303 , callback);
222
3c257afd68e7 plugins.pubsub: New, OOP-ish, PubSub interface. Beware of stubs.
Kim Alvefur <zash@zash.se>
parents: 221
diff changeset
304 end