plugins/presence.lua

Sat, 04 Jun 2016 13:36:39 +0200

author
Kim Alvefur <zash@zash.se>
date
Sat, 04 Jun 2016 13:36:39 +0200
changeset 405
f065fc1fab0a
parent 404
7c6a610c3ff5
child 406
3c732f1d990c
permissions
-rw-r--r--

plugins.presence: Have option keys mirror the tag names (keeping compat with previous behaviour)

250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 197
diff changeset
1 local verse = require "verse";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 197
diff changeset
2
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
3 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
4 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
5
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: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
7 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
8 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
9 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
10 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
11
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 function stream:resend_presence()
404
7c6a610c3ff5 plugins.presence: Fix resending previous presence
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
13 if self.last_presence then
7c6a610c3ff5 plugins.presence: Fix resending previous presence
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
14 stream:send(self.last_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
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 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
17
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 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
19 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
20 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
21 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
22 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
23 end
405
f065fc1fab0a plugins.presence: Have option keys mirror the tag names (keeping compat with previous behaviour)
Kim Alvefur <zash@zash.se>
parents: 404
diff changeset
24 if opts.priority or opts.prio then
f065fc1fab0a plugins.presence: Have option keys mirror the tag names (keeping compat with previous behaviour)
Kim Alvefur <zash@zash.se>
parents: 404
diff changeset
25 p:tag("priority"):text(tostring(opts.priority or 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
26 end
405
f065fc1fab0a plugins.presence: Have option keys mirror the tag names (keeping compat with previous behaviour)
Kim Alvefur <zash@zash.se>
parents: 404
diff changeset
27 if opts.status or opts.msg then
f065fc1fab0a plugins.presence: Have option keys mirror the tag names (keeping compat with previous behaviour)
Kim Alvefur <zash@zash.se>
parents: 404
diff changeset
28 p:tag("status"):text(opts.status or opts.msg):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
29 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
30 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
31 -- 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
32 -- 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
33
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 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
35 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
36 end

mercurial