examples/lm/attention.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Wed, 31 Mar 2010 01:25:19 +0300
changeset 99 ed4676536ed9
parent 68 742878c74b8e
permissions -rw-r--r--
Update most useful scripts * new hooks interface * connection state checking


-- ATTENTION (XEP-0224)

-- library

local lm = require 'lm'

--

local O = {
	handler =
		function ( mesg, from )
		end,
}

local F = { }

function F.send ( conn, to, message )
	local body = nil
	if message then
		body = { message }
	end
	conn:send (
		lm.message.create { mtype = 'message-headline', to = to,
			attention = { xmlns = 'urn:xmpp:attention:0' },
			body = body,
		} )
end

function F.handler ( handler )
	O.handler = handler
end

function F.message_handler ( conn, mess )
	local a = mess:child ( 'attention' )
	if a and a:attribute ( 'xmlns' ) == 'urn:xmpp:attention:0' then
		local body = mess:child ( 'body' )
		if body then
			body = body:value ()
		end
		O.handler ( body, mess:attribute ( "from" ) )
	end
	return false
end

return F

-- vim: se ts=4: --