Diff

util/pubsub.lua @ 4366:b6c18cadd3ec

util.pubsub: Add service:remove_all_subscriptions()
author Matthew Wild <mwild1@gmail.com>
date Tue, 30 Aug 2011 15:48:16 -0400
parent 4365:6704b3cd032e
child 4367:98b258b7d5dc
line wrap: on
line diff
--- a/util/pubsub.lua	Tue Aug 30 15:03:27 2011 -0400
+++ b/util/pubsub.lua	Tue Aug 30 15:48:16 2011 -0400
@@ -171,6 +171,32 @@
 	return true;
 end
 
+function service:remove_all_subscriptions(actor, jid)
+	-- Access checking
+	local cap;
+	if actor == true or jid == actor or self:jids_equal(actor, jid) then
+		cap = "unsubscribe";
+	else
+		cap = "unsubscribe_other";
+	end
+	if not self:may(node, actor, cap) then
+		return false, "forbidden";
+	end
+	if not self:may(node, jid, "be_unsubscribed") then
+		return false, "forbidden";
+	end
+	--
+	local normal_jid = self.config.normalize_jid(jid);
+	local subs = self.subscriptions[normal_jid]
+	subs = subs and subs[jid];
+	if subs then
+		for node in pairs(subs) do
+			self:remove_subscription(node, true, jid);
+		end
+	end
+	return true;
+end
+
 function service:get_subscription(node, actor, jid)
 	-- Access checking
 	local cap;