Annotate

plugins/presence.lua @ 191:e0664081654c

plugins.presence: Fix priority setting. (Thanks Florob)
author Kim Alvefur <zash@zash.se>
date Mon, 07 Mar 2011 21:53:02 +0100
parent 177:0ffb565fcfd6
child 197:7e98cf2c1d8d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
177
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local st = require "util.stanza"
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 function verse.plugins.presence(stream)
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 stream.last_presence = nil;
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 stream:hook("presence-out", function (presence)
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 if not presence.attr.to then
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 stream.last_presence = presence; -- Cache non-directed presence
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 end, 1);
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 function stream:resend_presence()
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 if last_presence then
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 stream:send(last_presence);
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 -- Becase I didn't find util.stanza in the client code.
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 -- And, then the name fits better :)
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 -- // Zash
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 function stream:set_status(opts)
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 local p = st.presence();
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 if type(opts) == "table" then
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 if opts.show then
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 p:tag("show"):text(opts.show):up();
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 if opts.prio then
191
e0664081654c plugins.presence: Fix priority setting. (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 177
diff changeset
27 p:tag("priority"):text(tostring(opts.prio)):up();
177
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 if opts.msg then
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 p:tag("status"):text(opts.msg):up();
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 -- TODO maybe use opts as prio if it's a int,
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 -- or as show or status if it's a string?
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 stream:send(p);
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end