examples/lm/attention.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


-- 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: --