Software / code / prosody-modules
Comparison
mod_cloud_notify/mod_cloud_notify.lua @ 4827:fe5303da99cb
mod_cloud_notify: Include extra error details if available
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 19 Dec 2021 01:33:34 +0100 |
| parent | 4730:1da4b815d2fe |
| child | 4968:487f1eb829cf |
comparison
equal
deleted
inserted
replaced
| 4826:3a5fbb6c61b3 | 4827:fe5303da99cb |
|---|---|
| 72 -- Forward declarations, as both functions need to reference each other | 72 -- Forward declarations, as both functions need to reference each other |
| 73 local handle_push_success, handle_push_error; | 73 local handle_push_success, handle_push_error; |
| 74 | 74 |
| 75 function handle_push_error(event) | 75 function handle_push_error(event) |
| 76 local stanza = event.stanza; | 76 local stanza = event.stanza; |
| 77 local error_type, condition = stanza:get_error(); | 77 local error_type, condition, error_text = stanza:get_error(); |
| 78 local node = id2node[stanza.attr.id]; | 78 local node = id2node[stanza.attr.id]; |
| 79 local identifier = id2identifier[stanza.attr.id]; | 79 local identifier = id2identifier[stanza.attr.id]; |
| 80 if node == nil then return false; end -- unknown stanza? Ignore for now! | 80 if node == nil then return false; end -- unknown stanza? Ignore for now! |
| 81 local from = stanza.attr.from; | 81 local from = stanza.attr.from; |
| 82 local user_push_services = push_store:get(node); | 82 local user_push_services = push_store:get(node); |
| 84 | 84 |
| 85 for push_identifier, _ in pairs(user_push_services) do | 85 for push_identifier, _ in pairs(user_push_services) do |
| 86 if push_identifier == identifier then | 86 if push_identifier == identifier then |
| 87 if user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type ~= "wait" then | 87 if user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type ~= "wait" then |
| 88 push_errors[push_identifier] = push_errors[push_identifier] + 1; | 88 push_errors[push_identifier] = push_errors[push_identifier] + 1; |
| 89 module:log("info", "Got error of type '%s' (%s) for identifier '%s': " | 89 module:log("info", "Got error <%s:%s:%s> for identifier '%s': " |
| 90 .."error count for this identifier is now at %s", error_type, condition, push_identifier, | 90 .."error count for this identifier is now at %s", error_type, condition, error_text or "", push_identifier, |
| 91 tostring(push_errors[push_identifier])); | 91 tostring(push_errors[push_identifier])); |
| 92 if push_errors[push_identifier] >= max_push_errors then | 92 if push_errors[push_identifier] >= max_push_errors then |
| 93 module:log("warn", "Disabling push notifications for identifier '%s'", push_identifier); | 93 module:log("warn", "Disabling push notifications for identifier '%s'", push_identifier); |
| 94 -- remove push settings from sessions | 94 -- remove push settings from sessions |
| 95 if host_sessions[node] then | 95 if host_sessions[node] then |
| 110 module:unhook("iq-result/host/"..stanza.attr.id, handle_push_success); | 110 module:unhook("iq-result/host/"..stanza.attr.id, handle_push_success); |
| 111 id2node[stanza.attr.id] = nil; | 111 id2node[stanza.attr.id] = nil; |
| 112 id2identifier[stanza.attr.id] = nil; | 112 id2identifier[stanza.attr.id] = nil; |
| 113 end | 113 end |
| 114 elseif user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type == "wait" then | 114 elseif user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type == "wait" then |
| 115 module:log("debug", "Got error of type '%s' (%s) for identifier '%s': " | 115 module:log("debug", "Got error <%s:%s:%s> for identifier '%s': " |
| 116 .."NOT increasing error count for this identifier", error_type, condition, push_identifier); | 116 .."NOT increasing error count for this identifier", error_type, condition, error_text or "", push_identifier); |
| 117 end | 117 end |
| 118 end | 118 end |
| 119 end | 119 end |
| 120 if changed then | 120 if changed then |
| 121 push_store:flush_to_disk(node); | 121 push_store:flush_to_disk(node); |