Software /
code /
verse
Annotate
plugins/presence.lua @ 443:89526c890363
libs.hashes: Add back pure Lua sha1 implementation
This one is slow so it gets to be first so it gets replaced if a better
lib is found.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 17 Feb 2021 14:57:59 +0100 |
parent | 406:3c732f1d990c |
child | 476:c34b263499be |
rev | line source |
---|---|
250 | 1 local verse = require "verse"; |
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 |
406
3c732f1d990c
plugins.presence: If a string is given as presece options, use it as status
Kim Alvefur <zash@zash.se>
parents:
405
diff
changeset
|
30 elseif type(opts) == "string" then |
3c732f1d990c
plugins.presence: If a string is given as presece options, use it as status
Kim Alvefur <zash@zash.se>
parents:
405
diff
changeset
|
31 p:tag("status"):text(opts):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
|
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 |
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 |