68
|
1 |
|
|
2 |
-- ATTENTION (XEP-0224) |
|
3 |
|
|
4 |
-- library |
|
5 |
|
|
6 |
local lm = require 'lm' |
|
7 |
|
|
8 |
-- |
|
9 |
|
|
10 |
local O = { |
|
11 |
handler = |
|
12 |
function ( mesg ) |
|
13 |
end, |
|
14 |
} |
|
15 |
|
|
16 |
local F = { } |
|
17 |
|
|
18 |
function F.send ( conn, to, message ) |
|
19 |
local body = nil |
|
20 |
if message then |
|
21 |
body = { message } |
|
22 |
end |
|
23 |
conn:send ( |
|
24 |
lm.message.create { mtype = 'message-headline', to = to, |
|
25 |
attention = { xmlns = 'urn:xmpp:attention:0' }, |
|
26 |
body = body, |
|
27 |
} ) |
|
28 |
end |
|
29 |
|
|
30 |
function F.handler ( handler ) |
|
31 |
O.handler = handler |
|
32 |
end |
|
33 |
|
|
34 |
function F.message_handler ( conn, mess ) |
|
35 |
local a = mess:child ( 'attention' ) |
|
36 |
if a and a:attribute ( 'xmlns' ) == 'urn:xmpp:attention:0' then |
|
37 |
local body = mess:child ( 'body' ) |
|
38 |
if body then |
|
39 |
body = body:value () |
|
40 |
end |
|
41 |
O.handler ( body ) |
|
42 |
end |
|
43 |
return false |
|
44 |
end |
|
45 |
|
|
46 |
return F |
|
47 |
|
|
48 |
-- vim: se ts=4: -- |