[fix] handle errorMessage in mailserver.request.completed signal

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
yenda 2018-11-22 10:22:02 +01:00 committed by Igor Mandrigin
parent 4aa562f6a8
commit 9110a64dcc
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
9 changed files with 93 additions and 24 deletions

View File

@ -358,9 +358,19 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:mailserver.ui/reconnect-mailserver-pressed :mailserver.ui/reconnect-mailserver-pressed
(fn [cofx [_ args]] (fn [cofx _]
(mailserver/connect-to-mailserver cofx))) (mailserver/connect-to-mailserver cofx)))
(handlers/register-handler-fx
:mailserver.ui/request-error-pressed
(fn [cofx _]
(mailserver/show-request-error-popup cofx)))
(handlers/register-handler-fx
:mailserver.ui/retry-request-pressed
(fn [cofx [_ args]]
(mailserver/retry-next-messages-request cofx)))
(handlers/register-handler-fx (handlers/register-handler-fx
:mailserver/check-connection-timeout :mailserver/check-connection-timeout
(fn [cofx _] (fn [cofx _]

View File

@ -440,6 +440,38 @@
mailserver-topics)} mailserver-topics)}
(process-next-messages-request)))))) (process-next-messages-request))))))
(fx/defn retry-next-messages-request
[{:keys [db] :as cofx}]
(fx/merge cofx
{:db (dissoc db :mailserver/request-error)}
(process-next-messages-request)))
(fx/defn handle-request-error
[{:keys [db]} error]
{:db (-> db
(assoc :mailserver/request-error error)
(dissoc :mailserver/current-request
:mailserver/pending-requests))})
(fx/defn handle-request-completed
[cofx event]
(when (accounts.db/logged-in? cofx)
(let [error (:errorMessage event)]
(if (empty? error)
(update-mailserver-topics cofx
{:request-id (:requestID event)
:cursor (:cursor event)})
(handle-request-error cofx error)))))
(fx/defn show-request-error-popup
[{:keys [db]}]
(let [mailserver-error (:mailserver/request-error db)]
{:utils/show-confirmation
{:title (i18n/label :t/mailserver-request-error-title)
:content (i18n/label :t/mailserver-request-error-content {:error mailserver-error})
:on-accept #(re-frame/dispatch [:mailserver.ui/retry-request-pressed])
:confirm-button-text (i18n/label :t/mailserver-request-retry)}}))
(fx/defn upsert-mailserver-topic (fx/defn upsert-mailserver-topic
"if the topic didn't exist "if the topic didn't exist
create the topic create the topic

View File

@ -40,3 +40,4 @@
(spec/def :mailserver/current-request (spec/keys :req-un [:request/from :request/to ::topics] (spec/def :mailserver/current-request (spec/keys :req-un [:request/from :request/to ::topics]
:opt-un [:request/attemps])) :opt-un [:request/attemps]))
(spec/def :mailserver/pending-requests integer?) (spec/def :mailserver/pending-requests integer?)
(spec/def :mailserver/request-error string?)

View File

@ -22,11 +22,16 @@
pending-requests))) pending-requests)))
(re-frame/reg-sub (re-frame/reg-sub
:mailserver/error :mailserver/connection-error?
:<- [:mailserver/state] :<- [:mailserver/state]
(fn [state] (fn [state]
(#{:error :disconnected} state))) (#{:error :disconnected} state)))
(re-frame/reg-sub
:mailserver/request-error?
(fn [db]
(get db :mailserver/request-error)))
(re-frame/reg-sub (re-frame/reg-sub
:mailserver/current-id :mailserver/current-id
(fn [db] (fn [db]

View File

@ -58,9 +58,7 @@
"envelope.sent" (transport.message/update-envelope-status cofx (:hash event) :sent) "envelope.sent" (transport.message/update-envelope-status cofx (:hash event) :sent)
"envelope.expired" (transport.message/update-envelope-status cofx (:hash event) :not-sent) "envelope.expired" (transport.message/update-envelope-status cofx (:hash event) :not-sent)
"bundles.added" (pairing/handle-bundles-added cofx event) "bundles.added" (pairing/handle-bundles-added cofx event)
"mailserver.request.completed" (when (accounts.db/logged-in? cofx) "mailserver.request.completed" (mailserver/handle-request-completed cofx event)
(mailserver/update-mailserver-topics cofx {:request-id (:requestID event)
:cursor (:cursor event)}))
"mailserver.request.expired" (when (accounts.db/logged-in? cofx) "mailserver.request.expired" (when (accounts.db/logged-in? cofx)
(mailserver/resend-request cofx {:request-id (:hash event)})) (mailserver/resend-request cofx {:request-id (:hash event)}))
"discovery.summary" (summary cofx event) "discovery.summary" (summary cofx event)

View File

@ -7,7 +7,8 @@
[status-im.i18n :as i18n])) [status-im.i18n :as i18n]))
(defview error-label (defview error-label
[{:keys [view-id label mailserver-fetching? mailserver-error?] :as opts}] [{:keys [view-id label mailserver-fetching? mailserver-connection-error?
mailserver-request-error?] :as opts}]
{:should-component-update {:should-component-update
(fn [_ [_ old-props] [_ new-props]] (fn [_ [_ old-props] [_ new-props]]
;; prevents flickering on navigation ;; prevents flickering on navigation
@ -17,9 +18,13 @@
[react/view {:style wrapper-style [react/view {:style wrapper-style
:accessibility-label :connection-status-text} :accessibility-label :connection-status-text}
[react/text {:style styles/text [react/text {:style styles/text
:on-press (when mailserver-error? :on-press #(cond
#(re-frame/dispatch [:mailserver.ui/reconnect-mailserver-pressed]))} mailserver-connection-error?
(if (and (not mailserver-error?) (re-frame/dispatch [:mailserver.ui/reconnect-mailserver-pressed])
mailserver-request-error?
(re-frame/dispatch [:mailserver.ui/request-error-pressed]))}
(if (and (not (or mailserver-connection-error?
mailserver-request-error?))
mailserver-fetching?) mailserver-fetching?)
(i18n/label :t/fetching-messages {:requests-left (str mailserver-fetching?)}) (i18n/label :t/fetching-messages {:requests-left (str mailserver-fetching?)})
(i18n/label label))]])) (i18n/label label))]]))
@ -27,7 +32,8 @@
(defview error-view [{:keys [top]}] (defview error-view [{:keys [top]}]
(letsubs [offline? [:offline?] (letsubs [offline? [:offline?]
disconnected? [:disconnected?] disconnected? [:disconnected?]
mailserver-error? [:mailserver/error] mailserver-connection-error? [:mailserver/connection-error?]
mailserver-request-error? [:mailserver/request-error?]
mailserver-fetching? [:mailserver/fetching?] mailserver-fetching? [:mailserver/fetching?]
current-chat-contact [:chats/current-chat-contact] current-chat-contact [:chats/current-chat-contact]
view-id [:get :view-id] view-id [:get :view-id]
@ -35,7 +41,8 @@
(when-let [label (cond (when-let [label (cond
offline? :t/offline offline? :t/offline
disconnected? :t/disconnected disconnected? :t/disconnected
mailserver-error? :t/mailserver-reconnect mailserver-connection-error? :t/mailserver-reconnect
mailserver-request-error? :t/mailserver-request-error-status
mailserver-fetching? :t/fetching-messages mailserver-fetching? :t/fetching-messages
:else nil)] :else nil)]
(let [pending? (and (:pending current-chat-contact) (= :chat view-id))] (let [pending? (and (:pending current-chat-contact) (= :chat view-id))]
@ -46,4 +53,5 @@
:pending? pending? :pending? pending?
:label label :label label
:mailserver-fetching? mailserver-fetching? :mailserver-fetching? mailserver-fetching?
:mailserver-error? mailserver-error?}])))) :mailserver-request-error? mailserver-request-error?
:mailserver-connection-error? mailserver-connection-error?}]))))

View File

@ -248,6 +248,7 @@
:mailserver/current-request :mailserver/current-request
:mailserver/connection-checks :mailserver/connection-checks
:mailserver/request-to :mailserver/request-to
:mailserver/request-error
:desktop/desktop :desktop/desktop
:dimensions/window :dimensions/window
:dapps/permissions :dapps/permissions

View File

@ -40,6 +40,16 @@
:accessibility-label :confirm-button}) :accessibility-label :confirm-button})
#js {:cancelable false}))) #js {:cancelable false})))
(re-frame/reg-fx
:utils/show-confirmation
(fn [{:keys [title content confirm-button-text on-accept on-cancel cancel-button-text]}]
(show-confirmation {:title title
:content content
:confirm-button-text confirm-button-text
:cancel-button-text cancel-button-text
:on-accept on-accept
:on-cancel on-cancel})))
(defn show-question (defn show-question
([title content on-accept] ([title content on-accept]
(show-question title content on-accept nil)) (show-question title content on-accept nil))

View File

@ -595,6 +595,10 @@
"currency-display-name-cny": "China Yuan Renminbi", "currency-display-name-cny": "China Yuan Renminbi",
"clear-history-confirmation-content": "Are you sure you want to clear this chat history?", "clear-history-confirmation-content": "Are you sure you want to clear this chat history?",
"mailserver-reconnect": "Could not connect to mailserver. Tap to reconnect", "mailserver-reconnect": "Could not connect to mailserver. Tap to reconnect",
"mailserver-request-error-status": "An error occured while fetching history, check the logs for details",
"mailserver-request-error-title": "Mailserver request error",
"mailserver-request-error-content": "The following error was returned by the mailserver: {{error}}",
"mailserver-request-retry": "Retry request",
"transactions": "Transactions", "transactions": "Transactions",
"transactions-unsigned": "Unsigned", "transactions-unsigned": "Unsigned",
"members": { "members": {