plugins/presence.lua

changeset 177
0ffb565fcfd6
child 191
e0664081654c
equal deleted inserted replaced
176:6004486e8b6c 177:0ffb565fcfd6
1 local st = require "util.stanza"
2 function verse.plugins.presence(stream)
3 stream.last_presence = nil;
4
5 stream:hook("presence-out", function (presence)
6 if not presence.attr.to then
7 stream.last_presence = presence; -- Cache non-directed presence
8 end
9 end, 1);
10
11 function stream:resend_presence()
12 if last_presence then
13 stream:send(last_presence);
14 end
15 end
16
17 -- Becase I didn't find util.stanza in the client code.
18 -- And, then the name fits better :)
19 -- // Zash
20 function stream:set_status(opts)
21 local p = st.presence();
22 if type(opts) == "table" then
23 if opts.show then
24 p:tag("show"):text(opts.show):up();
25 end
26 if opts.prio then
27 p:tag("priority"):text(opts.priority):up();
28 end
29 if opts.msg then
30 p:tag("status"):text(opts.msg):up();
31 end
32 end
33 -- TODO maybe use opts as prio if it's a int,
34 -- or as show or status if it's a string?
35
36 stream:send(p);
37 end
38 end

mercurial