Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
3910:80fe910f912a | 3911:a99a2bb7a6ec |
---|---|
42 | 42 |
43 function handlers.get_items(origin, stanza, items) | 43 function handlers.get_items(origin, stanza, items) |
44 local node = items.attr.node; | 44 local node = items.attr.node; |
45 local item = items:get_child("item"); | 45 local item = items:get_child("item"); |
46 local id = item and item.attr.id; | 46 local id = item and item.attr.id; |
47 | |
48 local ok, results = service:get_items(node, stanza.attr.from, id); | |
49 if not ok then | |
50 return origin.send(pubsub_error_reply(stanza, results)); | |
51 end | |
52 | |
47 local data = st.stanza("items", { node = node }); | 53 local data = st.stanza("items", { node = node }); |
48 for _, entry in pairs(service:get(node, stanza.attr.from, id)) do | 54 for _, entry in pairs(results) do |
49 data:add_child(entry); | 55 data:add_child(entry); |
50 end | 56 end |
51 if data then | 57 if data then |
52 reply = st.reply(stanza) | 58 reply = st.reply(stanza) |
53 :tag("pubsub", { xmlns = xmlns_pubsub }) | 59 :tag("pubsub", { xmlns = xmlns_pubsub }) |
70 end | 76 end |
71 else | 77 else |
72 repeat | 78 repeat |
73 node = uuid_generate(); | 79 node = uuid_generate(); |
74 ok, ret = service:create(node, stanza.attr.from); | 80 ok, ret = service:create(node, stanza.attr.from); |
75 until ok; | 81 until ok or ret ~= "conflict"; |
76 reply = st.reply(stanza) | 82 if ok then |
77 :tag("pubsub", { xmlns = xmlns_pubsub }) | 83 reply = st.reply(stanza) |
78 :tag("create", { node = node }); | 84 :tag("pubsub", { xmlns = xmlns_pubsub }) |
85 :tag("create", { node = node }); | |
86 else | |
87 reply = pubsub_error_reply(stanza, ret); | |
88 end | |
79 end | 89 end |
80 return origin.send(reply); | 90 return origin.send(reply); |
81 end | 91 end |
82 | 92 |
83 function handlers.set_subscribe(origin, stanza, subscribe) | 93 function handlers.set_subscribe(origin, stanza, subscribe) |
189 event.origin.send(reply); | 199 event.origin.send(reply); |
190 end | 200 end |
191 return true; | 201 return true; |
192 end); | 202 end); |
193 | 203 |
204 local admin_aff = module:get_option_string("default_admin_affiliation", "owner"); | |
205 local function get_affiliation(jid) | |
206 if usermanager.is_admin(jid, module.host) then | |
207 return admin_aff; | |
208 end | |
209 end | |
210 | |
194 service = pubsub.new({ | 211 service = pubsub.new({ |
195 broadcaster = simple_broadcast | 212 capabilities = { |
213 none = { | |
214 create = false; | |
215 publish = false; | |
216 retract = false; | |
217 get_nodes = true; | |
218 | |
219 subscribe = true; | |
220 unsubscribe = true; | |
221 get_subscription = true; | |
222 --get_items = true; | |
223 | |
224 subscribe_other = false; | |
225 unsubscribe_other = false; | |
226 get_subscription_other = false; | |
227 | |
228 be_subscribed = true; | |
229 be_unsubscribed = true; | |
230 | |
231 set_affiliation = false; | |
232 }; | |
233 owner = { | |
234 create = true; | |
235 publish = true; | |
236 retract = true; | |
237 get_nodes = true; | |
238 | |
239 subscribe = true; | |
240 unsubscribe = true; | |
241 get_subscription = true; | |
242 --get_items = true; | |
243 | |
244 | |
245 subscribe_other = true; | |
246 unsubscribe_other = true; | |
247 get_subscription_other = true; | |
248 | |
249 be_subscribed = true; | |
250 be_unsubscribed = true; | |
251 | |
252 set_affiliation = true; | |
253 }; | |
254 admin = { get_items = true }; | |
255 }; | |
256 | |
257 autocreate_on_publish = module:get_option_boolean("autocreate_on_publish"); | |
258 autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe"); | |
259 | |
260 broadcaster = simple_broadcast; | |
261 get_affiliation = get_affiliation; | |
262 jids_equal = function (jid1, jid2) | |
263 return jid_bare(jid1) == jid_bare(jid2); | |
264 end; | |
196 }); | 265 }); |
197 module.environment.service = service; | 266 module.environment.service = service; |
198 | 267 |
199 function module.save() | 268 function module.save() |
200 return { service = service }; | 269 return { service = service }; |