Mercurial > prosody-modules
annotate mod_smacks_offline/mod_smacks_offline.lua @ 3495:5567098a7f91
mod_conversejs/README: Update text about mod_bosh and mod_websocket
2681f74750b2 made the text slightly misleading since either connection
methods can be disabled
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 24 Mar 2019 03:24:49 +0100 |
parents | b912cb8e0b3c |
children | a3693e0d26b8 |
rev | line source |
---|---|
1702
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local t_insert = table.insert; |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local mod_smacks = module:depends"smacks" |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local function store_unacked_stanzas(session) |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local queue = session.outgoing_stanza_queue; |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local replacement_queue = {}; |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 session.outgoing_stanza_queue = replacement_queue; |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 for _, stanza in ipairs(queue) do |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 if stanza.name == "message" and stanza.attr.xmlns == nil and |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 ( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 module:fire_event("message/offline/handle", { origin = session, stanza = stanza } ) |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 else |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 t_insert(replacement_queue, stanza); |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 end |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 end |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 end |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local handle_unacked_stanzas = mod_smacks.handle_unacked_stanzas; |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 local host_sessions = prosody.hosts[module.host].sessions; |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 mod_smacks.handle_unacked_stanzas = function (session) |
1731
b912cb8e0b3c
mod_smacks_offline: Only deal with authenticated (c2s) sessions
Kim Alvefur <zash@zash.se>
parents:
1702
diff
changeset
|
24 if session.username then |
b912cb8e0b3c
mod_smacks_offline: Only deal with authenticated (c2s) sessions
Kim Alvefur <zash@zash.se>
parents:
1702
diff
changeset
|
25 local sessions = host_sessions[session.username].sessions; |
b912cb8e0b3c
mod_smacks_offline: Only deal with authenticated (c2s) sessions
Kim Alvefur <zash@zash.se>
parents:
1702
diff
changeset
|
26 if next(sessions) == session.resource and next(sessions, session.resource) == nil then |
b912cb8e0b3c
mod_smacks_offline: Only deal with authenticated (c2s) sessions
Kim Alvefur <zash@zash.se>
parents:
1702
diff
changeset
|
27 store_unacked_stanzas(session) |
b912cb8e0b3c
mod_smacks_offline: Only deal with authenticated (c2s) sessions
Kim Alvefur <zash@zash.se>
parents:
1702
diff
changeset
|
28 end |
1702
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 return handle_unacked_stanzas(session); |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 end |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 function module.unload() |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 mod_smacks.handle_unacked_stanzas = handle_unacked_stanzas; |
725ebd494000
mod_smacks_offline: Monkeypatch mod_smacks to send unacked messages to offline storage IFF there was only one session
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 end |