mod_pubsub: Support item retraction

Sun, 05 Dec 2010 04:19:23 +0100

author
Florian Zeitz <florob@babelmonkeys.de>
date
Sun, 05 Dec 2010 04:19:23 +0100
changeset 3699
150e58d69e60
parent 3698
77171fd1dc3c
child 3700
c8fcd63e9526

mod_pubsub: Support item retraction

plugins/mod_pubsub.lua file | annotate | diff | comparison | revisions
util/pubsub.lua file | annotate | diff | comparison | revisions
--- a/plugins/mod_pubsub.lua	Sun Dec 05 02:46:08 2010 +0100
+++ b/plugins/mod_pubsub.lua	Sun Dec 05 04:19:23 2010 +0100
@@ -76,7 +76,7 @@
 			:tag("pubsub", { xmlns = xmlns_pubsub })
 				:tag("create", { node = node });
 	end
-	origin.send(reply);
+	return origin.send(reply);
 end
 
 function handlers.set_subscribe(origin, stanza, subscribe)
@@ -132,6 +132,24 @@
 	return origin.send(reply);
 end
 
+function handlers.set_retract(origin, stanza, retract)
+	local node, notify = retract.attr.node, retract.attr.notify;
+	notify = (notify == "1") or (notify == "true");
+	local item = retract:get_child("item");
+	local id = item and item.attr.id
+	local reply, notifier;
+	if notify then
+		notifier = st.stanza("retract", { id = id });
+	end
+	local ok, ret = service:retract(node, stanza.attr.from, id, notifier);
+	if ok then
+		reply = st.reply(stanza);
+	else
+		reply = pubsub_error_reply(stanza, ret);
+	end
+	return origin.send(reply);
+end
+
 function simple_broadcast(node, jids, item)
 	local message = st.message({ from = module.host, type = "headline" })
 		:tag("event", { xmlns = xmlns_pubsub_event })
--- a/util/pubsub.lua	Sun Dec 05 02:46:08 2010 +0100
+++ b/util/pubsub.lua	Sun Dec 05 04:19:23 2010 +0100
@@ -54,6 +54,18 @@
 	return true;
 end
 
+function service:retract(node, actor, id, retract)
+	local node_obj = self.nodes[node];
+	if (not node_obj) or (not node_obj.data[id]) then
+		return false, "item-not-found";
+	end
+	node_obj.data[id] = nil;
+	if retract then
+		self.cb.broadcaster(node, node_obj.subscribers, retract);
+	end
+	return true
+end
+
 function service:get(node, actor, id)
 	local node_obj = self.nodes[node];
 	if node_obj then

mercurial