examples/transports.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Wed, 28 Nov 2012 20:17:53 +0200
changeset 146 04d19c9c1196
parent 99 ed4676536ed9
permissions -rw-r--r--
Fix module loading problem


-- TRANSPORTED BUDDIES AVAILABILITY INDICATION

-- XXX: to option?
transport_jids = { 'icq.jabber.kiev.ua', 'mrim.unixzone.org.ua' }

function online ( jid )
	local info = main.buddy_info ( jid )
	if not info then
		return false
	end
	for resource, params in pairs ( info.resources ) do
		if params.status ~= '_' then
			return true
		end
	end
	return false
end

local transports_pc_handler =
	function ( args )
		for k, jid in pairs ( transport_jids ) do
			if args.jid == jid then
				if args.new_status == '_' then
					main.run ( ("color roster * *@%s red"):format ( jid ) )
					main.run ( ("color roster dn_? *@%s red"):format ( jid ) )
				else
					main.run ( ("color roster * *@%s white"):format ( jid ) )
					main.run ( ("color roster dn_? *@%s brightblack"):format ( jid ) )
				end
			end
		end
	end

main.hook ( 'hook-lua-start',
	function ( args )
		for k, jid in pairs ( transport_jids ) do
			if not online ( jid ) then
				main.run ( ("color roster * *@%s red"):format ( jid ) )
				main.run ( ("color roster dn_? *@%s red"):format ( jid ) )
			else
				main.run ( ("color roster * *@%s white"):format ( jid ) )
				main.run ( ("color roster dn_? *@%s brightblack"):format ( jid ) )
			end
		end
	end )
main.hook ( 'hook-status-change', transports_pc_handler )
main.hook ( 'hook-post-connect',  transports_pc_handler )

main.hook ( 'hook-pre-disconnect',
	function ( args )
		for k, jid in pairs ( transport_jids ) do
			-- when disconnected, all buddies are inaccessible, so, make them the same
			main.run ( ("color roster * *@%s white"):format ( jid ) )
			main.run ( ("color roster dn_? *@%s brightblack"):format ( jid ) )
		end
	end )

-- vim: se ts=4 sw=4: --