verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking

Mon, 14 Jun 2010 14:12:44 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 14 Jun 2010 14:12:44 +0100
changeset 80
336864e83991
parent 79
da06d4996992
child 81
0924a3d05e40

verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking

plugins/blocking.lua file | annotate | diff | comparison | revisions
squishy file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/blocking.lua	Mon Jun 14 14:12:44 2010 +0100
@@ -0,0 +1,44 @@
+local xmlns_blocking = "urn:xmpp:blocking";
+
+function verse.plugins.blocking(stream)
+	-- FIXME: Disco
+	stream.blocking = {};
+	function stream.blocking:block_jid(jid, callback)
+		stream:send_iq(verse.iq{type="set"}
+			:tag("block", { xmlns = xmlns_blocking })
+				:tag("item", { jid = jid })
+			, function () return callback and callback(true); end
+			, function () return callback and callback(false); end
+		);
+	end
+	function stream.blocking:unblock_jid(jid, callback)
+		stream:send_iq(verse.iq{type="set"}
+			:tag("unblock", { xmlns = xmlns_blocking })
+				:tag("item", { jid = jid })
+			, function () return callback and callback(true); end
+			, function () return callback and callback(false); end
+		);
+	end
+	function stream.blocking:unblock_all_jids(callback)
+		stream:send_iq(verse.iq{type="set"}
+			:tag("unblock", { xmlns = xmlns_blocking })
+			, function () return callback and callback(true); end
+			, function () return callback and callback(false); end
+		);
+	end
+	function stream.blocking:get_blocked_jids(callback)
+		stream:send_iq(verse.iq{type="get"}
+			:tag("blocklist", { xmlns = xmlns_blocking })
+			, function (result)
+				local list = result:get_child("blocklist", xmlns_blocking);
+				if not list then return callback and callback(false); end
+				local jids = {};
+				for item in list:childtags() do
+					jids[#jids+1] = item.attr.jid;
+				end
+				return callback and callback(jids);
+			  end
+			, function (result) return callback and callback(false); end
+		);
+	end
+end
--- a/squishy	Fri Jun 04 10:36:34 2010 +0100
+++ b/squishy	Mon Jun 14 14:12:44 2010 +0100
@@ -26,6 +26,7 @@
 Module "verse.plugins.ping"	   "plugins/ping.lua"
 Module "verse.plugins.session"     "plugins/session.lua"
 Module "verse.plugins.compression" "plugins/compression.lua"
+Module "verse.plugins.blocking"    "plugins/blocking.lua"
 
 Module "verse.client" "client.lua"
 

mercurial