Handle mailserver connection error

* Do not try to reconnect when offline
* If online, but mailserver is disconnected, show notification
* Tap on notification starts reconnecting process

Signed-off-by: Eric Dvorsak <eric@dvorsak.fr>
This commit is contained in:
Dmitry Novotochinov 2018-05-11 14:00:02 +03:00 committed by Eric Dvorsak
parent a57b0e6136
commit cd41cefa96
No known key found for this signature in database
GPG Key ID: 932AC1CE5F05DE0C
4 changed files with 34 additions and 19 deletions

View File

@ -8,6 +8,7 @@
:notifications-title "Notifications and sounds" :notifications-title "Notifications and sounds"
:offline "Offline" :offline "Offline"
:connection-problem "Messages connection problem" :connection-problem "Messages connection problem"
:mailserver-reconnect "Could not connect to mailserver. Tap to reconnect"
:search-for "Search for..." :search-for "Search for..."
:cancel "Cancel" :cancel "Cancel"
:next "Next" :next "Next"

View File

@ -173,25 +173,31 @@
(fn [_ [_ retries]] (fn [_ [_ retries]]
{::fetch-peers (or retries 0)})) {::fetch-peers (or retries 0)}))
(def ^:private ^:const short-retry-delay-ms 300)
(def ^:private ^:const long-retry-delay-ms 5000)
(def ^:private ^:const max-retries 10)
(def ^:private ^:const retries-interval-change-threshold 3)
(handlers/register-handler-fx (handlers/register-handler-fx
:inbox/check-peer-added :inbox/check-peer-added
;; We check if the wnode is part of the peers list ;; We check if the wnode is part of the peers list
;; if not we dispatch a new fetch-peer event for later ;; if not we dispatch a new fetch-peer event for later
(fn [{:keys [db]} [_ peers retries]] (fn [{{:keys [web3 network-status] :as db} :db} [_ peers retries]]
(let [web3 (:web3 db) (let [wnode (get-current-wnode-address db)]
wnode (get-current-wnode-address db)]
(log/info "offline inbox: fetch-peers response" peers) (log/info "offline inbox: fetch-peers response" peers)
(if (registered-peer? peers wnode) (if (registered-peer? peers wnode)
{::mark-trusted-peer {:web3 web3 {::mark-trusted-peer {:web3 web3
:wnode wnode}} :wnode wnode}}
(do (do
(log/info "Peer" wnode "is not registered. Retrying fetch peers.") (log/info "Peer" wnode "is not registered. Retrying fetch peers.")
(let [delay (if (< retries 3) 300 5000)] (let [delay-ms (if (< retries retries-interval-change-threshold)
(if (> retries 10) short-retry-delay-ms
(do (log/error :mailserver-connection-error) long-retry-delay-ms)]
(utils/show-popup (i18n/label :t/error) (if (or (= network-status :offline)
(i18n/label :t/mailserver-connection-error))) (> retries max-retries))
{:dispatch-later [{:ms delay :dispatch [:inbox/fetch-peers (inc retries)]}]}))))))) (do (log/info :mailserver-connection-error)
{:db (assoc db :mailserver-status :disconnected)})
{:dispatch-later [{:ms delay-ms :dispatch [:inbox/fetch-peers (inc retries)]}]})))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:inbox/get-sym-key :inbox/get-sym-key
@ -234,3 +240,8 @@
:sym-key-id sym-key-id :sym-key-id sym-key-id
:web3 web3} :web3 web3}
:db (assoc db :inbox/last-request (quot now 1000))}))) :db (assoc db :inbox/last-request (quot now 1000))})))
(handlers/register-handler-fx
:inbox/reconnect
(fn [cofx _]
(recover-offline-inbox true cofx)))

View File

@ -1,7 +1,7 @@
(ns status-im.ui.components.connectivity.styles (ns status-im.ui.components.connectivity.styles
(:require-macros [status-im.utils.styles :refer [defnstyle]])) (:require-macros [status-im.utils.styles :refer [defnstyle]]))
(defnstyle offline-wrapper [top opacity window-width pending?] (defnstyle text-wrapper [top opacity window-width pending?]
{:ios {:z-index 0} {:ios {:z-index 0}
:opacity opacity :opacity opacity
:width window-width :width window-width
@ -10,7 +10,7 @@
:background-color "#828b92cc" :background-color "#828b92cc"
:height 35}) :height 35})
(def offline-text (def text
{:text-align :center {:text-align :center
:color :white :color :white
:font-size 14 :font-size 14

View File

@ -31,11 +31,14 @@
:display-name "connectivity-error-view" :display-name "connectivity-error-view"
:reagent-render :reagent-render
(fn [{:keys [top]}] (fn [{:keys [top]}]
(when (or @offline? @connection-problem?) (when-let [label (cond
@offline? :t/offline
@connection-problem? :t/mailserver-reconnect
:else nil)]
(let [pending? (and (:pending @current-chat-contact) (= :chat @view-id))] (let [pending? (and (:pending @current-chat-contact) (= :chat @view-id))]
[react/animated-view {:style (styles/offline-wrapper top offline-opacity window-width pending?)} [react/animated-view {:style (styles/text-wrapper top offline-opacity window-width pending?)}
[react/view [react/view
[react/text {:style styles/offline-text} [react/text {:style styles/text
(i18n/label (if @connection-problem? :on-press (when @connection-problem?
:t/connection-problem #(re-frame/dispatch [:inbox/reconnect]))}
:t/offline))]]])))}))) (i18n/label label)]]])))})))