Annotate

plugins/mod_pubsub.lua @ 3911:a99a2bb7a6ec

mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
author Matthew Wild <mwild1@gmail.com>
date Tue, 21 Dec 2010 03:27:22 +0000
parent 3908:4d8081c35f01
child 3912:dfc9789f9016
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local pubsub = require "util.pubsub";
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local st = require "util.stanza";
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local jid_bare = require "util.jid".bare;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local uuid_generate = require "util.uuid".generate;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 require "core.modulemanager".load(module.host, "iq");
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local service;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local handlers = {};
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 function handle_pubsub_iq(event)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local origin, stanza = event.origin, event.stanza;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local pubsub = stanza.tags[1];
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local action = pubsub.tags[1];
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local handler = handlers[stanza.attr.type.."_"..action.name];
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 if handler then
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 handler(origin, stanza, action);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 return true;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 local pubsub_errors = {
3697
67c01f75af97 mod_pubsub: Use pubsub_error_reply everywhere
Florian Zeitz <florob@babelmonkeys.de>
parents: 3672
diff changeset
28 ["conflict"] = { "cancel", "conflict" };
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" };
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 ["item-not-found"] = { "cancel", "item-not-found" };
3698
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
31 ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" };
3908
4d8081c35f01 mod_pubsub: Add 'forbidden' error support
Matthew Wild <mwild1@gmail.com>
parents: 3761
diff changeset
32 ["forbidden"] = { "cancel", "forbidden" };
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 };
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 function pubsub_error_reply(stanza, error)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 local e = pubsub_errors[error];
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 local reply = st.error_reply(stanza, unpack(e, 1, 3));
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 if e[4] then
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up();
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 return reply;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
3641
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
43 function handlers.get_items(origin, stanza, items)
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
44 local node = items.attr.node;
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
45 local item = items:get_child("item");
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
46 local id = item and item.attr.id;
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
47
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
48 local ok, results = service:get_items(node, stanza.attr.from, id);
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
49 if not ok then
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
50 return origin.send(pubsub_error_reply(stanza, results));
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
51 end
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
52
3641
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
53 local data = st.stanza("items", { node = node });
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
54 for _, entry in pairs(results) do
3641
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
55 data:add_child(entry);
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
56 end
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
57 if data then
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
58 reply = st.reply(stanza)
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
59 :tag("pubsub", { xmlns = xmlns_pubsub })
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
60 :add_child(data);
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
61 else
3697
67c01f75af97 mod_pubsub: Use pubsub_error_reply everywhere
Florian Zeitz <florob@babelmonkeys.de>
parents: 3672
diff changeset
62 reply = pubsub_error_reply(stanza, "item-not-found");
3641
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
63 end
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
64 return origin.send(reply);
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
65 end
3603aeb325de mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents: 3622
diff changeset
66
3672
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
67 function handlers.set_create(origin, stanza, create)
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
68 local node = create.attr.node;
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
69 local ok, ret, reply;
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
70 if node then
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
71 ok, ret = service:create(node, stanza.attr.from);
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
72 if ok then
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
73 reply = st.reply(stanza);
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
74 else
3697
67c01f75af97 mod_pubsub: Use pubsub_error_reply everywhere
Florian Zeitz <florob@babelmonkeys.de>
parents: 3672
diff changeset
75 reply = pubsub_error_reply(stanza, ret);
3672
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
76 end
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
77 else
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
78 repeat
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
79 node = uuid_generate();
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
80 ok, ret = service:create(node, stanza.attr.from);
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
81 until ok or ret ~= "conflict";
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
82 if ok then
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
83 reply = st.reply(stanza)
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
84 :tag("pubsub", { xmlns = xmlns_pubsub })
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
85 :tag("create", { node = node });
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
86 else
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
87 reply = pubsub_error_reply(stanza, ret);
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
88 end
3672
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
89 end
3699
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
90 return origin.send(reply);
3672
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
91 end
b24db47995ac mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 3641
diff changeset
92
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 function handlers.set_subscribe(origin, stanza, subscribe)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 local node, jid = subscribe.attr.node, subscribe.attr.jid;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 if jid_bare(jid) ~= jid_bare(stanza.attr.from) then
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 return origin.send(pubsub_error_reply(stanza, "invalid-jid"));
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 local ok, ret = service:add_subscription(node, stanza.attr.from, jid);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 local reply;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 if ok then
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 reply = st.reply(stanza)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 :tag("pubsub", { xmlns = xmlns_pubsub })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 :tag("subscription", {
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 node = node,
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 jid = jid,
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 subscription = "subscribed"
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 });
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 else
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 reply = pubsub_error_reply(stanza, ret);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 return origin.send(reply);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113
3698
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
114 function handlers.set_unsubscribe(origin, stanza, unsubscribe)
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
115 local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid;
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
116 if jid_bare(jid) ~= jid_bare(stanza.attr.from) then
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
117 return origin.send(pubsub_error_reply(stanza, "invalid-jid"));
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
118 end
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
119 local ok, ret = service:remove_subscription(node, stanza.attr.from, jid);
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
120 local reply;
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
121 if ok then
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
122 reply = st.reply(stanza);
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
123 else
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
124 reply = pubsub_error_reply(stanza, ret);
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
125 end
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
126 return origin.send(reply);
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
127 end
77171fd1dc3c mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents: 3697
diff changeset
128
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 function handlers.set_publish(origin, stanza, publish)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 local node = publish.attr.node;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 local item = publish:get_child("item");
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 local id = (item and item.attr.id) or uuid_generate();
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 local ok, ret = service:publish(node, stanza.attr.from, id, item);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 local reply;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 if ok then
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 reply = st.reply(stanza)
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 :tag("pubsub", { xmlns = xmlns_pubsub })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 :tag("publish", { node = node })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 :tag("item", { id = id });
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 else
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 reply = pubsub_error_reply(stanza, ret);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 return origin.send(reply);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145
3699
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
146 function handlers.set_retract(origin, stanza, retract)
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
147 local node, notify = retract.attr.node, retract.attr.notify;
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
148 notify = (notify == "1") or (notify == "true");
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
149 local item = retract:get_child("item");
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
150 local id = item and item.attr.id
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
151 local reply, notifier;
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
152 if notify then
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
153 notifier = st.stanza("retract", { id = id });
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
154 end
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
155 local ok, ret = service:retract(node, stanza.attr.from, id, notifier);
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
156 if ok then
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
157 reply = st.reply(stanza);
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
158 else
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
159 reply = pubsub_error_reply(stanza, ret);
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
160 end
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
161 return origin.send(reply);
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
162 end
150e58d69e60 mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents: 3698
diff changeset
163
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 function simple_broadcast(node, jids, item)
3700
c8fcd63e9526 mod_pubsub: Ensure <item> is in correct scope when broadcasting an event
Matthew Wild <mwild1@gmail.com>
parents: 3699
diff changeset
165 item = st.clone(item);
c8fcd63e9526 mod_pubsub: Ensure <item> is in correct scope when broadcasting an event
Matthew Wild <mwild1@gmail.com>
parents: 3699
diff changeset
166 item.attr.xmlns = nil; -- Clear the pubsub namespace
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 local message = st.message({ from = module.host, type = "headline" })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 :tag("event", { xmlns = xmlns_pubsub_event })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 :tag("items", { node = node })
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 :add_child(item);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 for jid in pairs(jids) do
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 module:log("debug", "Sending notification to %s", jid);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 message.attr.to = jid;
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 core_post_stanza(hosts[module.host], message);
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 end
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177
3621
7e1a1dd42088 mod_pubsub: Expose 'service'
Matthew Wild <mwild1@gmail.com>
parents: 3619
diff changeset
178 module:hook("iq/host/http://jabber.org/protocol/pubsub:pubsub", handle_pubsub_iq);
7e1a1dd42088 mod_pubsub: Expose 'service'
Matthew Wild <mwild1@gmail.com>
parents: 3619
diff changeset
179
3760
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
180 local disco_info = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info" })
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
181 :tag("identity", { category = "pubsub", type = "service" }):up()
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
182 :tag("feature", { var = "http://jabber.org/protocol/pubsub" }):up();
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
183
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
184 module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function (event)
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
185 event.origin.send(st.reply(event.stanza):add_child(disco_info));
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
186 return true;
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
187 end);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
188
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
189 module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function (event)
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
190 local ok, ret = service:get_nodes(event.stanza.attr.from);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
191 if not ok then
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
192 event.origin.send(pubsub_error_reply(stanza, ret));
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
193 else
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
194 local reply = st.reply(event.stanza)
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
195 :tag("query", { xmlns = "http://jabber.org/protocol/disco#items" });
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
196 for node, node_obj in pairs(ret) do
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
197 reply:tag("item", { jid = module.host, node = node, name = node_obj.config.name }):up();
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
198 end
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
199 event.origin.send(reply);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
200 end
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
201 return true;
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
202 end);
3bfb65496773 mod_pubsub: Handle disco#info and disco#items
Matthew Wild <mwild1@gmail.com>
parents: 3700
diff changeset
203
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
204 local admin_aff = module:get_option_string("default_admin_affiliation", "owner");
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
205 local function get_affiliation(jid)
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
206 if usermanager.is_admin(jid, module.host) then
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
207 return admin_aff;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
208 end
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
209 end
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
210
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
211 service = pubsub.new({
3911
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
212 capabilities = {
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
213 none = {
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
214 create = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
215 publish = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
216 retract = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
217 get_nodes = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
218
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
219 subscribe = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
220 unsubscribe = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
221 get_subscription = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
222 --get_items = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
223
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
224 subscribe_other = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
225 unsubscribe_other = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
226 get_subscription_other = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
227
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
228 be_subscribed = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
229 be_unsubscribed = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
230
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
231 set_affiliation = false;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
232 };
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
233 owner = {
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
234 create = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
235 publish = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
236 retract = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
237 get_nodes = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
238
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
239 subscribe = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
240 unsubscribe = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
241 get_subscription = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
242 --get_items = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
243
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
244
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
245 subscribe_other = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
246 unsubscribe_other = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
247 get_subscription_other = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
248
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
249 be_subscribed = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
250 be_unsubscribed = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
251
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
252 set_affiliation = true;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
253 };
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
254 admin = { get_items = true };
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
255 };
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
256
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
257 autocreate_on_publish = module:get_option_boolean("autocreate_on_publish");
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
258 autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe");
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
259
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
260 broadcaster = simple_broadcast;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
261 get_affiliation = get_affiliation;
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
262 jids_equal = function (jid1, jid2)
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
263 return jid_bare(jid1) == jid_bare(jid2);
a99a2bb7a6ec mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
Matthew Wild <mwild1@gmail.com>
parents: 3908
diff changeset
264 end;
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
265 });
3622
418354197a02 mod_pubsub: Use module.environment to reference the module's environment
Matthew Wild <mwild1@gmail.com>
parents: 3621
diff changeset
266 module.environment.service = service;
3619
291ae816d800 mod_pubsub: It's aliiiive!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
267
3761
e5fb26e8faeb mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents: 3760
diff changeset
268 function module.save()
e5fb26e8faeb mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents: 3760
diff changeset
269 return { service = service };
e5fb26e8faeb mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents: 3760
diff changeset
270 end
e5fb26e8faeb mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents: 3760
diff changeset
271
e5fb26e8faeb mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents: 3760
diff changeset
272 function module.restore(data)
e5fb26e8faeb mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents: 3760
diff changeset
273 service = data.service;
e5fb26e8faeb mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents: 3760
diff changeset
274 module.environment.service = service;
e5fb26e8faeb mod_pubsub: Preserve service object on module reload
Matthew Wild <mwild1@gmail.com>
parents: 3760
diff changeset
275 end