Software / code / verse
Annotate
plugins/presence.lua @ 239:65a0d3fcbbad
verse: Switch connection ids to be a simple incrementing integer
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 27 Nov 2011 22:48:02 +0000 |
| parent | 197:7e98cf2c1d8d |
| child | 250:a5ac643a7fd6 |
| 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 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
|
2 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
|
3 |
|
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 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
|
5 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
|
6 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
|
7 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
|
8 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
|
9 |
|
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 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
|
11 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
|
12 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
|
13 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
|
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 |
|
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 function stream:set_status(opts) |
|
197
7e98cf2c1d8d
plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents:
191
diff
changeset
|
17 local p = verse.presence(); |
|
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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 if opts.prio then |
|
191
e0664081654c
plugins.presence: Fix priority setting. (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
177
diff
changeset
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
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 -- 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
|
30 -- 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
|
31 |
|
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 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
|
33 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
|
34 end |