fix: fix mailserver popup showing after canceling it

Fixes #10065
After clicking cancel, the popup is `dismissed`, so it will not appear again
Selecting a new mail server sets `dismissed` as false, so the error can appear again
This commit is contained in:
Jonathan Rainville 2020-04-15 14:59:19 -04:00 committed by Andrea Maria Piana
parent a6e08f0d8e
commit b2cdc59670
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 36 additions and 20 deletions

View File

@ -220,6 +220,11 @@
(fn [cofx [_ current-fleet mailserver-id]] (fn [cofx [_ current-fleet mailserver-id]]
(mailserver/save-settings 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 (handlers/register-handler-fx
:mailserver.ui/unpin-pressed :mailserver.ui/unpin-pressed
(fn [cofx _] (fn [cofx _]

View File

@ -59,6 +59,9 @@
(defn preferred-mailserver-id [db] (defn preferred-mailserver-id [db]
(get-in db [:multiaccount :pinned-mailservers (node/current-fleet-key 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] (defn mailserver-address->id [db address]
(let [current-fleet (node/current-fleet-key db)] (let [current-fleet (node/current-fleet-key db)]
(:id (some #(when (= address (:address %)) (:id (some #(when (= address (:address %))
@ -526,13 +529,17 @@
;; instead of using pos? ;; instead of using pos?
(not (zero? (:peers-count db)))) (not (zero? (:peers-count db))))
(if-let [preferred-mailserver (preferred-mailserver-id 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 {:db
(update-mailserver-state db :error) (update-mailserver-state db :error)
:ui/show-confirmation :ui/show-confirmation
(when-not error-dismissed
{:title (i18n/label :t/mailserver-error-title) {:title (i18n/label :t/mailserver-error-title)
:content (i18n/label :t/mailserver-error-content) :content (i18n/label :t/mailserver-error-content)
:confirm-button-text (i18n/label :t/mailserver-pick-another) :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 :on-accept #(re-frame/dispatch
[:navigate-to :offline-messaging-settings]) [:navigate-to :offline-messaging-settings])
:extra-options [{:text (i18n/label :t/mailserver-retry) :extra-options [{:text (i18n/label :t/mailserver-retry)
@ -540,7 +547,7 @@
[:mailserver.ui/connect-confirmed [:mailserver.ui/connect-confirmed
current-fleet current-fleet
preferred-mailserver]) preferred-mailserver])
:style "default"}]}}) :style "default"}]})})
(let [{:keys [address]} (fetch-current db)] (let [{:keys [address]} (fetch-current db)]
(fx/merge cofx (fx/merge cofx
{:mailserver/remove-peer address} {:mailserver/remove-peer address}
@ -1133,6 +1140,9 @@
(assoc (set-input cofx :url url) (assoc (set-input cofx :url url)
:dispatch [:navigate-back])) :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 (fx/defn save-settings
[{:keys [db] :as cofx} current-fleet mailserver-id] [{:keys [db] :as cofx} current-fleet mailserver-id]
(let [{:keys [address]} (fetch-current db) (let [{:keys [address]} (fetch-current db)
@ -1143,9 +1153,8 @@
(fx/merge cofx (fx/merge cofx
{:db (assoc db :mailserver/current-id mailserver-id) {:db (assoc db :mailserver/current-id mailserver-id)
:mailserver/remove-peer address} :mailserver/remove-peer address}
(when use-mailservers? (connect-to-mailserver)) (when use-mailservers? (connect-to-mailserver))
(dismiss-connection-error false)
(when pinned? (when pinned?
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:pinned-mailservers (assoc pinned-mailservers :pinned-mailservers (assoc pinned-mailservers
@ -1161,6 +1170,7 @@
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:pinned-mailservers (dissoc pinned-mailservers current-fleet) :pinned-mailservers (dissoc pinned-mailservers current-fleet)
{}) {})
(dismiss-connection-error false)
(change-mailserver)))) (change-mailserver))))
(fx/defn pin (fx/defn pin
@ -1168,12 +1178,13 @@
(let [current-fleet (node/current-fleet-key db) (let [current-fleet (node/current-fleet-key db)
mailserver-id (:mailserver/current-id db) mailserver-id (:mailserver/current-id db)
pinned-mailservers (get-in db [:multiaccount :pinned-mailservers])] pinned-mailservers (get-in db [:multiaccount :pinned-mailservers])]
(fx/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
cofx
:pinned-mailservers (assoc pinned-mailservers :pinned-mailservers (assoc pinned-mailservers
current-fleet current-fleet
mailserver-id) mailserver-id)
{}))) {})
(dismiss-connection-error false))))
(fx/defn load-gaps-fx [{:keys [db] :as cofx} chat-id] (fx/defn load-gaps-fx [{:keys [db] :as cofx} chat-id]
(when-not (get-in db [:gaps-loaded? chat-id]) (when-not (get-in db [:gaps-loaded? chat-id])