diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 1a9571eeab..0e5d232d83 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -220,6 +220,11 @@ (fn [cofx [_ current-fleet mailserver-id]] (mailserver/save-settings cofx current-fleet mailserver-id))) +(handlers/register-handler-fx + :mailserver.ui/dismiss-connection-error + (fn [cofx [_ new-state]] + (mailserver/dismiss-connection-error cofx new-state))) + (handlers/register-handler-fx :mailserver.ui/unpin-pressed (fn [cofx _] diff --git a/src/status_im/mailserver/core.cljs b/src/status_im/mailserver/core.cljs index a5440e4f41..1a6694d7a1 100644 --- a/src/status_im/mailserver/core.cljs +++ b/src/status_im/mailserver/core.cljs @@ -59,6 +59,9 @@ (defn preferred-mailserver-id [db] (get-in db [:multiaccount :pinned-mailservers (node/current-fleet-key db)])) +(defn connection-error-dismissed [db] + (get-in db [:mailserver/connection-error-dismissed])) + (defn mailserver-address->id [db address] (let [current-fleet (node/current-fleet-key db)] (:id (some #(when (= address (:address %)) @@ -526,21 +529,25 @@ ;; instead of using pos? (not (zero? (:peers-count db)))) (if-let [preferred-mailserver (preferred-mailserver-id db)] - (let [current-fleet (node/current-fleet-key db)] + (let [error-dismissed (connection-error-dismissed db) + current-fleet (node/current-fleet-key db)] + ;; Error connecting to the mail server {:db (update-mailserver-state db :error) :ui/show-confirmation - {:title (i18n/label :t/mailserver-error-title) - :content (i18n/label :t/mailserver-error-content) - :confirm-button-text (i18n/label :t/mailserver-pick-another) - :on-accept #(re-frame/dispatch - [:navigate-to :offline-messaging-settings]) - :extra-options [{:text (i18n/label :t/mailserver-retry) - :onPress #(re-frame/dispatch - [:mailserver.ui/connect-confirmed - current-fleet - preferred-mailserver]) - :style "default"}]}}) + (when-not error-dismissed + {:title (i18n/label :t/mailserver-error-title) + :content (i18n/label :t/mailserver-error-content) + :confirm-button-text (i18n/label :t/mailserver-pick-another) + :on-cancel #(re-frame/dispatch [:mailserver.ui/dismiss-connection-error true]) + :on-accept #(re-frame/dispatch + [:navigate-to :offline-messaging-settings]) + :extra-options [{:text (i18n/label :t/mailserver-retry) + :onPress #(re-frame/dispatch + [:mailserver.ui/connect-confirmed + current-fleet + preferred-mailserver]) + :style "default"}]})}) (let [{:keys [address]} (fetch-current db)] (fx/merge cofx {:mailserver/remove-peer address} @@ -1133,6 +1140,9 @@ (assoc (set-input cofx :url url) :dispatch [:navigate-back])) +(fx/defn dismiss-connection-error [{:keys [db]} new-state] + {:db (assoc db :mailserver/connection-error-dismissed new-state)}) + (fx/defn save-settings [{:keys [db] :as cofx} current-fleet mailserver-id] (let [{:keys [address]} (fetch-current db) @@ -1143,9 +1153,8 @@ (fx/merge cofx {:db (assoc db :mailserver/current-id mailserver-id) :mailserver/remove-peer address} - (when use-mailservers? (connect-to-mailserver)) - + (dismiss-connection-error false) (when pinned? (multiaccounts.update/multiaccount-update :pinned-mailservers (assoc pinned-mailservers @@ -1161,6 +1170,7 @@ (multiaccounts.update/multiaccount-update :pinned-mailservers (dissoc pinned-mailservers current-fleet) {}) + (dismiss-connection-error false) (change-mailserver)))) (fx/defn pin @@ -1168,12 +1178,13 @@ (let [current-fleet (node/current-fleet-key db) mailserver-id (:mailserver/current-id db) pinned-mailservers (get-in db [:multiaccount :pinned-mailservers])] - (multiaccounts.update/multiaccount-update - cofx - :pinned-mailservers (assoc pinned-mailservers - current-fleet - mailserver-id) - {}))) + (fx/merge cofx + (multiaccounts.update/multiaccount-update + :pinned-mailservers (assoc pinned-mailservers + current-fleet + mailserver-id) + {}) + (dismiss-connection-error false)))) (fx/defn load-gaps-fx [{:keys [db] :as cofx} chat-id] (when-not (get-in db [:gaps-loaded? chat-id])