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"
:offline "Offline"
:connection-problem "Messages connection problem"
:mailserver-reconnect "Could not connect to mailserver. Tap to reconnect"
:search-for "Search for..."
:cancel "Cancel"
:next "Next"

View File

@ -173,25 +173,31 @@
(fn [_ [_ retries]]
{::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
:inbox/check-peer-added
;; We check if the wnode is part of the peers list
;; if not we dispatch a new fetch-peer event for later
(fn [{:keys [db]} [_ peers retries]]
(let [web3 (:web3 db)
wnode (get-current-wnode-address db)]
;; We check if the wnode is part of the peers list
;; if not we dispatch a new fetch-peer event for later
(fn [{{:keys [web3 network-status] :as db} :db} [_ peers retries]]
(let [wnode (get-current-wnode-address db)]
(log/info "offline inbox: fetch-peers response" peers)
(if (registered-peer? peers wnode)
{::mark-trusted-peer {:web3 web3
:wnode wnode}}
(do
(log/info "Peer" wnode "is not registered. Retrying fetch peers.")
(let [delay (if (< retries 3) 300 5000)]
(if (> retries 10)
(do (log/error :mailserver-connection-error)
(utils/show-popup (i18n/label :t/error)
(i18n/label :t/mailserver-connection-error)))
{:dispatch-later [{:ms delay :dispatch [:inbox/fetch-peers (inc retries)]}]})))))))
(let [delay-ms (if (< retries retries-interval-change-threshold)
short-retry-delay-ms
long-retry-delay-ms)]
(if (or (= network-status :offline)
(> retries max-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
:inbox/get-sym-key
@ -234,3 +240,8 @@
:sym-key-id sym-key-id
:web3 web3}
: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
(: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}
:opacity opacity
:width window-width
@ -10,7 +10,7 @@
:background-color "#828b92cc"
:height 35})
(def offline-text
(def text
{:text-align :center
:color :white
:font-size 14

View File

@ -31,11 +31,14 @@
:display-name "connectivity-error-view"
:reagent-render
(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))]
[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/text {:style styles/offline-text}
(i18n/label (if @connection-problem?
:t/connection-problem
:t/offline))]]])))})))
[react/text {:style styles/text
:on-press (when @connection-problem?
#(re-frame/dispatch [:inbox/reconnect]))}
(i18n/label label)]]])))})))