Software /
code /
prosody
Comparison
plugins/mod_pubsub.lua @ 5305:391b72fede9f
mod_pubsub, util.pubsub: Implement the purge action
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 24 Jan 2013 00:58:03 +0100 |
parent | 5304:67a49d47ef39 |
child | 5308:fd3219d64414 |
comparison
equal
deleted
inserted
replaced
5304:67a49d47ef39 | 5305:391b72fede9f |
---|---|
176 function handlers.set_retract(origin, stanza, retract) | 176 function handlers.set_retract(origin, stanza, retract) |
177 local node, notify = retract.attr.node, retract.attr.notify; | 177 local node, notify = retract.attr.node, retract.attr.notify; |
178 notify = (notify == "1") or (notify == "true"); | 178 notify = (notify == "1") or (notify == "true"); |
179 local item = retract:get_child("item"); | 179 local item = retract:get_child("item"); |
180 local id = item and item.attr.id | 180 local id = item and item.attr.id |
181 if not (node and id) then | |
182 origin.send(st.error_reply(stanza, "modify", "bad-request")); | |
183 return true; | |
184 end | |
181 local reply, notifier; | 185 local reply, notifier; |
182 if notify then | 186 if notify then |
183 notifier = st.stanza("retract", { id = id }); | 187 notifier = st.stanza("retract", { id = id }); |
184 end | 188 end |
185 local ok, ret = service:retract(node, stanza.attr.from, id, notifier); | 189 local ok, ret = service:retract(node, stanza.attr.from, id, notifier); |
190 if ok then | |
191 reply = st.reply(stanza); | |
192 else | |
193 reply = pubsub_error_reply(stanza, ret); | |
194 end | |
195 return origin.send(reply); | |
196 end | |
197 | |
198 function handlers.set_purge(origin, stanza, purge) | |
199 local node, notify = purge.attr.node, purge.attr.notify; | |
200 notify = (notify == "1") or (notify == "true"); | |
201 local reply, notifier; | |
202 if not node then | |
203 origin.send(st.error_reply(stanza, "modify", "bad-request")); | |
204 return true; | |
205 end | |
206 if notify then | |
207 notifier = st.stanza("purge"); | |
208 end | |
209 local ok, ret = service:purge(node, stanza.attr.from, notifier); | |
186 if ok then | 210 if ok then |
187 reply = st.reply(stanza); | 211 reply = st.reply(stanza); |
188 else | 212 else |
189 reply = pubsub_error_reply(stanza, ret); | 213 reply = pubsub_error_reply(stanza, ret); |
190 end | 214 end |
210 local disco_info; | 234 local disco_info; |
211 | 235 |
212 local feature_map = { | 236 local feature_map = { |
213 create = { "create-nodes", "instant-nodes", "item-ids" }; | 237 create = { "create-nodes", "instant-nodes", "item-ids" }; |
214 retract = { "delete-items", "retract-items" }; | 238 retract = { "delete-items", "retract-items" }; |
239 purge = { "purge-nodes" }; | |
215 publish = { "publish", autocreate_on_publish and "auto-create" }; | 240 publish = { "publish", autocreate_on_publish and "auto-create" }; |
216 get_items = { "retrieve-items" }; | 241 get_items = { "retrieve-items" }; |
217 add_subscription = { "subscribe" }; | 242 add_subscription = { "subscribe" }; |
218 get_subscriptions = { "retrieve-subscriptions" }; | 243 get_subscriptions = { "retrieve-subscriptions" }; |
219 }; | 244 }; |