examples/lm/attention.lua
changeset 68 742878c74b8e
child 99 ed4676536ed9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/lm/attention.lua	Tue Mar 31 18:35:34 2009 +0300
@@ -0,0 +1,48 @@
+
+-- ATTENTION (XEP-0224)
+
+-- library
+
+local lm = require 'lm'
+
+--
+
+local O = {
+	handler =
+		function ( mesg )
+		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 )
+	end
+	return false
+end
+
+return F
+
+-- vim: se ts=4: --