Mercurial > prosody-hg
comparison plugins/mod_presence.lua @ 13676:40c309f8b676 13.0
mod_presence: Fix traceback if origin gets disconnected during processing
Fixes #1887
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 13 Feb 2025 14:00:08 +0000 |
| parents | 74b9e05af71e |
| children |
comparison
equal
deleted
inserted
replaced
| 13674:1ba58459c919 | 13676:40c309f8b676 |
|---|---|
| 52 if priority and s_find(priority, "^[+-]?[0-9]+$") then | 52 if priority and s_find(priority, "^[+-]?[0-9]+$") then |
| 53 priority = tonumber(priority); | 53 priority = tonumber(priority); |
| 54 if priority < -128 then priority = -128 end | 54 if priority < -128 then priority = -128 end |
| 55 if priority > 127 then priority = 127 end | 55 if priority > 127 then priority = 127 end |
| 56 else priority = 0; end | 56 else priority = 0; end |
| 57 | |
| 58 local node, host = origin.username, origin.host; | |
| 59 local roster = origin.roster; | |
| 57 if full_sessions[origin.full_jid] then -- if user is still connected | 60 if full_sessions[origin.full_jid] then -- if user is still connected |
| 58 origin.send(stanza); -- reflect their presence back to them | 61 origin.send(stanza); -- reflect their presence back to them |
| 59 end | 62 end |
| 60 local roster = origin.roster; | |
| 61 local node, host = origin.username, origin.host; | |
| 62 local user = bare_sessions[node.."@"..host]; | 63 local user = bare_sessions[node.."@"..host]; |
| 63 for _, res in pairs(user and user.sessions or NULL) do -- broadcast to all resources | 64 for _, res in pairs(user and user.sessions or NULL) do -- broadcast to all resources |
| 64 if res ~= origin and res.presence then -- to resource | 65 if res ~= origin and res.presence then -- to resource |
| 65 stanza.attr.to = res.full_jid; | 66 stanza.attr.to = res.full_jid; |
| 66 core_post_stanza(origin, stanza, true); | 67 core_post_stanza(origin, stanza, true); |
| 70 if item.subscription == "both" or item.subscription == "from" then | 71 if item.subscription == "both" or item.subscription == "from" then |
| 71 stanza.attr.to = jid; | 72 stanza.attr.to = jid; |
| 72 core_post_stanza(origin, stanza, true); | 73 core_post_stanza(origin, stanza, true); |
| 73 end | 74 end |
| 74 end | 75 end |
| 76 | |
| 77 -- It's possible that after the network activity above, the origin | |
| 78 -- has been disconnected (particularly if something happened while | |
| 79 -- sending the reflection). So we abort further presence processing | |
| 80 -- in that case. | |
| 81 if not origin.type then return; end | |
| 82 | |
| 75 stanza.attr.to = nil; | 83 stanza.attr.to = nil; |
| 76 if stanza.attr.type == nil and not origin.presence then -- initial presence | 84 if stanza.attr.type == nil and not origin.presence then -- initial presence |
| 77 module:fire_event("presence/initial", { origin = origin, stanza = stanza } ); | 85 module:fire_event("presence/initial", { origin = origin, stanza = stanza } ); |
| 78 origin.presence = stanza; -- FIXME repeated later | 86 origin.presence = stanza; -- FIXME repeated later |
| 79 local probe = st.presence({from = origin.full_jid, type = "probe"}); | 87 local probe = st.presence({from = origin.full_jid, type = "probe"}); |
