Mercurial > prosody-hg
comparison plugins/mod_carbons.lua @ 10802:c11f9cd6c761
mod_carbons: Clarify handling of error bounces
The :find bit was hard to understand, this should be clearer.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 06 May 2020 12:48:09 +0200 |
| parents | a1b633ba9bd9 |
| children | 04a0aa6d7e72 |
comparison
equal
deleted
inserted
replaced
| 10801:2b97aac0ea3c | 10802:c11f9cd6c761 |
|---|---|
| 3 -- | 3 -- |
| 4 -- This file is MIT/X11 licensed. | 4 -- This file is MIT/X11 licensed. |
| 5 | 5 |
| 6 local st = require "util.stanza"; | 6 local st = require "util.stanza"; |
| 7 local jid_bare = require "util.jid".bare; | 7 local jid_bare = require "util.jid".bare; |
| 8 local jid_resource = require "util.jid".resource; | |
| 8 local xmlns_carbons = "urn:xmpp:carbons:2"; | 9 local xmlns_carbons = "urn:xmpp:carbons:2"; |
| 9 local xmlns_forward = "urn:xmpp:forward:0"; | 10 local xmlns_forward = "urn:xmpp:forward:0"; |
| 10 local full_sessions, bare_sessions = prosody.full_sessions, prosody.bare_sessions; | 11 local full_sessions, bare_sessions = prosody.full_sessions, prosody.bare_sessions; |
| 12 | |
| 13 local function is_bare(jid) | |
| 14 return not jid_resource(jid); | |
| 15 end | |
| 11 | 16 |
| 12 local function toggle_carbons(event) | 17 local function toggle_carbons(event) |
| 13 local origin, stanza = event.origin, event.stanza; | 18 local origin, stanza = event.origin, event.stanza; |
| 14 local state = stanza.tags[1].name; | 19 local state = stanza.tags[1].name; |
| 15 module:log("debug", "%s %sd carbons", origin.full_jid, state); | 20 module:log("debug", "%s %sd carbons", origin.full_jid, state); |
| 41 | 46 |
| 42 if st_type == "normal" and stanza:get_child("body") then | 47 if st_type == "normal" and stanza:get_child("body") then |
| 43 return true, "type"; | 48 return true, "type"; |
| 44 end | 49 end |
| 45 | 50 |
| 46 if st_type == "error" and not c2s and not (stanza.attr.from or ""):find("/") then | 51 -- Normal outgoing chat messages are sent to=bare JID. This clause should |
| 52 -- match the error bounces from those, which would have from=bare JID and | |
| 53 -- be incoming (not c2s). | |
| 54 if st_type == "error" and not c2s and is_bare(stanza.attr.from) then | |
| 47 return true, "bounce"; | 55 return true, "bounce"; |
| 48 end | 56 end |
| 49 | 57 |
| 50 for archived in stanza:childtags("stanza-id", "urn:xmpp:sid:0") do | 58 for archived in stanza:childtags("stanza-id", "urn:xmpp:sid:0") do |
| 51 if archived and archived.attr.by == user_bare then | 59 if archived and archived.attr.by == user_bare then |
