plugins/presence.lua

Fri, 31 Dec 2010 01:29:28 +0100

author
Kim Alvefur <zash@zash.se>
date
Fri, 31 Dec 2010 01:29:28 +0100
changeset 177
0ffb565fcfd6
child 191
e0664081654c
permissions
-rw-r--r--

plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast

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
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 p:tag("priority"):text(opts.priority):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
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

mercurial