author | Myhailo Danylenko <isbear@ukrpost.net> |
Wed, 31 Mar 2010 01:25:19 +0300 | |
changeset 99 | ed4676536ed9 |
parent 68 | 742878c74b8e |
permissions | -rw-r--r-- |
68 | 1 |
|
2 |
-- ATTENTION (XEP-0224) |
|
3 |
||
4 |
-- library |
|
5 |
||
6 |
local lm = require 'lm' |
|
7 |
||
8 |
-- |
|
9 |
||
10 |
local O = { |
|
11 |
handler = |
|
99
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
12 |
function ( mesg, from ) |
68 | 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 |
|
99
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
41 |
O.handler ( body, mess:attribute ( "from" ) ) |
68 | 42 |
end |
43 |
return false |
|
44 |
end |
|
45 |
||
46 |
return F |
|
47 |
||
48 |
-- vim: se ts=4: -- |