Fri, 17 Mar 2023 11:18:39 +0000
presence: Clone stanza before caching it
250 | 1 | local verse = require "verse"; |
476
c34b263499be
presence: Clone stanza before caching it
Matthew Wild <mwild1@gmail.com>
parents:
406
diff
changeset
|
2 | local st = require "util.stanza"; |
250 | 3 | |
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
|
4 | 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
|
5 | 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
|
6 | |
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: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
|
8 | if not presence.attr.to then |
476
c34b263499be
presence: Clone stanza before caching it
Matthew Wild <mwild1@gmail.com>
parents:
406
diff
changeset
|
9 | -- Clone so we don't add stuff over and over..? |
c34b263499be
presence: Clone stanza before caching it
Matthew Wild <mwild1@gmail.com>
parents:
406
diff
changeset
|
10 | stream.last_presence = st.clone(presence); -- Cache non-directed 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
|
11 | 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
|
12 | 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
|
13 | |
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 | function stream:resend_presence() |
404
7c6a610c3ff5
plugins.presence: Fix resending previous presence
Kim Alvefur <zash@zash.se>
parents:
250
diff
changeset
|
15 | if self.last_presence then |
7c6a610c3ff5
plugins.presence: Fix resending previous presence
Kim Alvefur <zash@zash.se>
parents:
250
diff
changeset
|
16 | 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
|
17 | 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
|
18 | 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
|
19 | |
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) |
197
7e98cf2c1d8d
plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents:
191
diff
changeset
|
21 | 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
|
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 |
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
|
26 | 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
|
27 | 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
|
28 | 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
|
29 | 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
|
30 | 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
|
31 | 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
|
32 | 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
|
33 | 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
|
34 | 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
|
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 |