plugins/presence.lua

Tue, 09 Feb 2016 23:39:31 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 09 Feb 2016 23:39:31 +0000
changeset 400
0db9cb909cf1
parent 250
a5ac643a7fd6
child 404
7c6a610c3ff5
permissions
-rw-r--r--

client, component: Fix logging of invalid XML

local verse = require "verse";

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

	function stream:set_status(opts)
		local p = verse.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(tostring(opts.prio)):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