Mercurial > prosody-modules
annotate mod_smacks_noerror/mod_smacks_noerror.lua @ 2670:6e01878103c0
mod_smacks: Ignore user when writing or reading session_cache on prosody 0.9
At least under some circumstances it seems that session.username is nil when
a user tries to resume his session in prosody 0.9.
The username is not relevant when no limiting is done (limiting the number of
entries in the session cache is only possible in prosody 0.10), so this
commit removes the usage of the username when accessing the prosody 0.9 session
cache.
| author | tmolitor <thilo@eightysoft.de> |
|---|---|
| date | Thu, 06 Apr 2017 02:12:14 +0200 |
| parents | d1e975c24545 |
| children | f35b2b76df6d |
| rev | line source |
|---|---|
|
2392
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
1 local t_insert = table.insert; |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
2 |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
3 local mod_smacks = module:depends"smacks" |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
4 |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
5 local function discard_unacked_messages(session) |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
6 local queue = session.outgoing_stanza_queue; |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
7 local replacement_queue = {}; |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
8 session.outgoing_stanza_queue = replacement_queue; |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
9 |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
10 for _, stanza in ipairs(queue) do |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
11 if stanza.name == "message" and stanza.attr.xmlns == nil and |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
12 ( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
13 -- do nothing here for normal messages and don't send out "message delivery errors", |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
14 -- because messages are already in MAM at this point (no need to frighten users) |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
15 else |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
16 t_insert(replacement_queue, stanza); |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
17 end |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
18 end |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
19 end |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
20 |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
21 local handle_unacked_stanzas = mod_smacks.handle_unacked_stanzas; |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
22 |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
23 mod_smacks.handle_unacked_stanzas = function (session) |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
24 -- Only deal with authenticated (c2s) sessions |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
25 if session.username then |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
26 discard_unacked_messages(session) |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
27 end |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
28 return handle_unacked_stanzas(session); |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
29 end |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
30 |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
31 function module.unload() |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
32 mod_smacks.handle_unacked_stanzas = handle_unacked_stanzas; |
|
d1e975c24545
mod_smacks_noerror: Initial commit
tmolitor <thilo@eightysoft.de>
parents:
diff
changeset
|
33 end |
