[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
:mailserver.ui/reconnect-mailserver-pressed
(fn [cofx [_ args]]
(fn [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
:mailserver/check-connection-timeout
(fn [cofx _]

View File

@ -440,6 +440,38 @@
mailserver-topics)}
(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
"if the topic didn't exist
create the topic

View File

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

View File

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

View File

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

View File

@ -7,7 +7,8 @@
[status-im.i18n :as i18n]))
(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
(fn [_ [_ old-props] [_ new-props]]
;; prevents flickering on navigation
@ -17,33 +18,40 @@
[react/view {:style wrapper-style
:accessibility-label :connection-status-text}
[react/text {:style styles/text
:on-press (when mailserver-error?
#(re-frame/dispatch [:mailserver.ui/reconnect-mailserver-pressed]))}
(if (and (not mailserver-error?)
:on-press #(cond
mailserver-connection-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?)
(i18n/label :t/fetching-messages {:requests-left (str mailserver-fetching?)})
(i18n/label label))]]))
(defview error-view [{:keys [top]}]
(letsubs [offline? [:offline?]
disconnected? [:disconnected?]
mailserver-error? [:mailserver/error]
mailserver-fetching? [:mailserver/fetching?]
current-chat-contact [:chats/current-chat-contact]
view-id [:get :view-id]
window-width [:dimensions/window-width]]
(letsubs [offline? [:offline?]
disconnected? [:disconnected?]
mailserver-connection-error? [:mailserver/connection-error?]
mailserver-request-error? [:mailserver/request-error?]
mailserver-fetching? [:mailserver/fetching?]
current-chat-contact [:chats/current-chat-contact]
view-id [:get :view-id]
window-width [:dimensions/window-width]]
(when-let [label (cond
offline? :t/offline
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
:else nil)]
(let [pending? (and (:pending current-chat-contact) (= :chat view-id))]
[error-label
{:view-id view-id
:top top
:window-width window-width
:pending? pending?
:label label
:mailserver-fetching? mailserver-fetching?
:mailserver-error? mailserver-error?}]))))
{:view-id view-id
:top top
:window-width window-width
:pending? pending?
:label label
:mailserver-fetching? mailserver-fetching?
:mailserver-request-error? mailserver-request-error?
:mailserver-connection-error? mailserver-connection-error?}]))))

View File

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

View File

@ -40,6 +40,16 @@
:accessibility-label :confirm-button})
#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
([title content on-accept]
(show-question title content on-accept nil))

View File

@ -595,6 +595,10 @@
"currency-display-name-cny": "China Yuan Renminbi",
"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-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-unsigned": "Unsigned",
"members": {