plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast

Fri, 31 Dec 2010 01:29:28 +0100

author
Kim Alvefur <zash@zash.se>
date
Fri, 31 Dec 2010 01:29:28 +0100
changeset 177
0ffb565fcfd6
parent 176
6004486e8b6c
child 178
2189f75e09b9

plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast

plugins/presence.lua file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/presence.lua	Fri Dec 31 01:29:28 2010 +0100
@@ -0,0 +1,38 @@
+local st = require "util.stanza"
+function verse.plugins.presence(stream)
+	stream.last_presence = nil;
+
+	stream:hook("presence-out", function (presence)
+		if not presence.attr.to then
+			stream.last_presence = presence; -- Cache non-directed presence
+		end
+	end, 1);
+
+	function stream:resend_presence()
+		if last_presence then
+			stream:send(last_presence);
+		end
+	end
+
+	-- Becase I didn't find util.stanza in the client code.
+	-- And, then the name fits better :)
+	-- // Zash
+	function stream:set_status(opts)
+		local p = st.presence();
+		if type(opts) == "table" then
+			if opts.show then
+				p:tag("show"):text(opts.show):up();
+			end
+			if opts.prio then
+				p:tag("priority"):text(opts.priority):up();
+			end
+			if opts.msg then
+				p:tag("status"):text(opts.msg):up();
+			end
+		end
+		-- TODO maybe use opts as prio if it's a int,
+		-- or as show or status if it's a string?
+
+		stream:send(p);
+	end
+end

mercurial