[fix 6334] request multiple topics at once

- group requests by last-request to request multiple topic at once
- fix bug where fetching popup was shown when the app was actually in error
state

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2018-10-16 13:32:16 +02:00
parent 55d72b534a
commit 69fe9dc582
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
6 changed files with 51 additions and 40 deletions

View File

@ -1 +1 @@
0.16.1 0.16.3

View File

@ -37,7 +37,7 @@ ExternalProject_Add(StatusGo_ep
PREFIX ${StatusGo_PREFIX} PREFIX ${StatusGo_PREFIX}
SOURCE_DIR ${StatusGo_SOURCE_DIR} SOURCE_DIR ${StatusGo_SOURCE_DIR}
GIT_REPOSITORY https://github.com/status-im/status-go.git GIT_REPOSITORY https://github.com/status-im/status-go.git
GIT_TAG 9f8f0089a3561e77b25279575928de8caba373cc GIT_TAG c86f8bf6ca35280e7041674f76a2ef1fe333e482
BUILD_BYPRODUCTS ${StatusGo_STATIC_LIB} BUILD_BYPRODUCTS ${StatusGo_STATIC_LIB}
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${CONFIGURE_SCRIPT} ${GO_ROOT_PATH} ${StatusGo_ROOT} ${StatusGo_SOURCE_DIR} CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${CONFIGURE_SCRIPT} ${GO_ROOT_PATH} ${StatusGo_ROOT} ${StatusGo_SOURCE_DIR}

View File

@ -56,8 +56,8 @@
"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) :sent) "envelope.expired" (transport.message/update-envelope-status cofx (:hash event) :sent)
"mailserver.request.completed" (when (accounts.db/logged-in? cofx) "mailserver.request.completed" (when (accounts.db/logged-in? cofx)
(inbox/update-inbox-topic cofx {:request-id (:requestID event) (inbox/update-inbox-topics cofx {:request-id (:requestID event)
:cursor (:cursor event)})) :cursor (:cursor event)}))
"mailserver.request.expired" (when (accounts.db/logged-in? cofx) "mailserver.request.expired" (when (accounts.db/logged-in? cofx)
(inbox/resend-request cofx {:request-id (:hash event)})) (inbox/resend-request cofx {:request-id (:hash event)}))
"discovery.summary" (summary cofx event) "discovery.summary" (summary cofx event)

View File

@ -15,6 +15,7 @@
;; optional ;; optional
(spec/def ::topic (spec/nilable string?)) (spec/def ::topic (spec/nilable string?))
(spec/def ::topics (spec/coll-of ::topic :min-count 1))
(spec/def ::sym-key-id (spec/nilable string?)) (spec/def ::sym-key-id (spec/nilable string?))
;;TODO (yenda) remove once go implements persistence ;;TODO (yenda) remove once go implements persistence
(spec/def ::sym-key (spec/nilable string?)) (spec/def ::sym-key (spec/nilable string?))
@ -25,8 +26,6 @@
(spec/def :request/to pos-int?) (spec/def :request/to pos-int?)
(spec/def :request/attemps int?) (spec/def :request/attemps int?)
(spec/def :request/cursor :global/not-empty-string) (spec/def :request/cursor :global/not-empty-string)
(spec/def :transport.inbox/request (spec/keys :req-un [:request/from :request/to ::topic]
:opt-un [:request/attemps]))
(spec/def :transport.inbox.topic/last-request pos-int?) (spec/def :transport.inbox.topic/last-request pos-int?)
(spec/def :transport.inbox.topic/started-at pos-int?) (spec/def :transport.inbox.topic/started-at pos-int?)
@ -36,18 +35,18 @@
:kind set? :kind set?
:min-count 1)) :min-count 1))
(spec/def :transport.inbox/topic (allowed-keys :req-un [:transport.inbox.topic/last-request (spec/def :transport.inbox/topic (spec/keys :req-un [:transport.inbox.topic/last-request
:transport.inbox.topic/chat-ids] :transport.inbox.topic/chat-ids]))
:opt-un [:transport.inbox.topic/started-at])) (spec/def :transport/chat (spec/keys :req-un [::ack ::seen ::pending-ack ::pending-send ::topic]
(spec/def :transport/chat (allowed-keys :req-un [::ack ::seen ::pending-ack ::pending-send ::topic] :opt-un [::sym-key-id ::sym-key ::resend?]))
:opt-un [::sym-key-id ::sym-key ::resend?]))
(spec/def :transport.inbox/request-to :request/to) (spec/def :transport.inbox/request-to :request/to)
(spec/def :transport/chats (spec/map-of :global/not-empty-string :transport/chat)) (spec/def :transport/chats (spec/map-of :global/not-empty-string :transport/chat))
(spec/def :transport/filters (spec/map-of :transport/filter-id :transport/filter)) (spec/def :transport/filters (spec/map-of :transport/filter-id :transport/filter))
(spec/def :transport.inbox/connection-checks pos-int?) (spec/def :transport.inbox/connection-checks pos-int?)
(spec/def :transport.inbox/topics (spec/map-of :global/not-empty-string :transport.inbox/topic)) (spec/def :transport.inbox/topics (spec/map-of :global/not-empty-string :transport.inbox/topic))
(spec/def :transport.inbox/current-request :transport.inbox/request) (spec/def :transport.inbox/current-request (spec/keys :req-un [:request/from :request/to ::topics]
:opt-un [:request/attemps]))
(spec/def :transport.inbox/pending-requests integer?) (spec/def :transport.inbox/pending-requests integer?)
(defn create-chat (defn create-chat

View File

@ -170,13 +170,13 @@
mailserver-removed? mailserver-removed?
(connect-to-mailserver cofx))))) (connect-to-mailserver cofx)))))
(defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topic to from]}] (defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics to from]}]
(log/info "offline inbox: request-messages for: " (log/info "offline inbox: request-messages for: "
" topic " topic " topics " topics
" from " from " from " from
" to " to) " to " to)
(.requestMessages (transport.utils/shh web3) (.requestMessages (transport.utils/shh web3)
(clj->js {:topic topic (clj->js {:topics topics
:mailServerPeer address :mailServerPeer address
:symKeyID sym-key-id :symKeyID sym-key-id
:timeout request-timeout :timeout request-timeout
@ -184,8 +184,8 @@
:to to}) :to to})
(fn [error request-id] (fn [error request-id]
(if-not error (if-not error
(log/info "offline inbox: messages request success for topic " topic "from" from "to" to) (log/info "offline inbox: messages request success for topic " topics "from" from "to" to)
(log/error "offline inbox: messages request error for topic " topic ": " error))))) (log/error "offline inbox: messages request error for topic " topics ": " error)))))
(re-frame/reg-fx (re-frame/reg-fx
:transport.inbox/request-messages :transport.inbox/request-messages
@ -205,7 +205,7 @@
"NOTE: currently the mailserver is only accepting requests for a span "NOTE: currently the mailserver is only accepting requests for a span
of 24 hours, so we split requests per 24h spans if the last request was of 24 hours, so we split requests per 24h spans if the last request was
done more than 24h ago" done more than 24h ago"
[now-in-s [topic {:keys [last-request]}]] [now-in-s [last-request topics]]
(let [days (conj (let [days (conj
(into [] (range (max last-request (into [] (range (max last-request
(- now-in-s one-day)) (- now-in-s one-day))
@ -214,7 +214,7 @@
now-in-s) now-in-s)
day-ranges (map vector days (rest days))] day-ranges (map vector days (rest days))]
(for [[from to] day-ranges] (for [[from to] day-ranges]
{:topic topic {:topics topics
:from from :from from
:to to}))) :to to})))
@ -223,7 +223,10 @@
(let [web3 (:web3 db)] (let [web3 (:web3 db)]
(remove nil? (remove nil?
(mapcat (partial split-request-per-day request-to) (mapcat (partial split-request-per-day request-to)
(:transport.inbox/topics db))))) (reduce (fn [acc [topic {:keys [last-request]}]]
(update acc last-request conj topic))
{}
(:transport.inbox/topics db))))))
(fx/defn process-next-messages-request (fx/defn process-next-messages-request
[{:keys [db now] :as cofx}] [{:keys [db now] :as cofx}]
@ -325,29 +328,38 @@
{:topic topic {:topic topic
:inbox-topic inbox-topic})]}))) :inbox-topic inbox-topic})]})))
(fx/defn update-inbox-topic (defn get-updated-inbox-topics [db topics last-request]
(reduce (fn [acc topic]
(if-let [inbox-topic (some-> (get-in db [:transport.inbox/topics topic])
(assoc :last-request last-request))]
(assoc acc topic inbox-topic)
acc))
{}
topics))
(fx/defn update-inbox-topics
"TODO: add support for cursors "TODO: add support for cursors
if there is a cursor, do not update `last-request`" if there is a cursor, do not update `last-request`"
[{:keys [db now] :as cofx} {:keys [request-id cursor]}] [{:keys [db now] :as cofx} {:keys [request-id]}]
(when-let [request (get db :transport.inbox/current-request)] (when-let [request (get db :transport.inbox/current-request)]
(let [{:keys [from to topic]} request (let [{:keys [from to topics]} request
inbox-topic (some-> (get-in db [:transport.inbox/topics topic]) inbox-topics (get-updated-inbox-topics db topics to)]
(assoc :last-request to))]
(log/info "offline inbox: message request " request-id (log/info "offline inbox: message request " request-id
"completed for inbox topic" topic "from" from "to" to) "completed for inbox topics" topics "from" from "to" to)
(if inbox-topic (if (empty? inbox-topics)
(fx/merge cofx ;; when topics were deleted (filter was removed while request was pending)
(if inbox-topic
{:db (-> db
(dissoc :transport.inbox/current-request)
(assoc-in [:transport.inbox/topics topic] inbox-topic))
:data-store/tx [(transport-store/save-transport-inbox-topic-tx
{:topic topic
:inbox-topic inbox-topic})]})
(process-next-messages-request))
;; when the topic was deleted (filter was removed while request was pending)
(fx/merge cofx (fx/merge cofx
{:db (dissoc db :transport.inbox/current-request)} {:db (dissoc db :transport.inbox/current-request)}
(process-next-messages-request))
(fx/merge cofx
{:db (-> db
(dissoc :transport.inbox/current-request)
(update :transport.inbox/topics merge inbox-topics))
:data-store/tx (mapv (fn [[topic inbox-topic]]
(transport-store/save-transport-inbox-topic-tx
{:topic topic
:inbox-topic inbox-topic}))
inbox-topics)}
(process-next-messages-request)))))) (process-next-messages-request))))))
(fx/defn upsert-inbox-topic (fx/defn upsert-inbox-topic
@ -378,9 +390,9 @@
{:db (update db :transport.inbox/current-request dissoc :attemps)} {:db (update db :transport.inbox/current-request dissoc :attemps)}
(change-mailserver)) (change-mailserver))
(when-let [wnode (get-wnode-when-ready cofx)] (when-let [wnode (get-wnode-when-ready cofx)]
(let [{:keys [topic from to] :as request} (get db :transport.inbox/current-request) (let [{:keys [topics from to] :as request} (get db :transport.inbox/current-request)
web3 (:web3 db)] web3 (:web3 db)]
(log/info "offline inbox: message request " request-id "expired for inbox topic" topic "from" from "to" to) (log/info "offline inbox: message request " request-id "expired for inbox topic" topics "from" from "to" to)
{:db (update-in db [:transport.inbox/current-request :attemps] inc) {:db (update-in db [:transport.inbox/current-request :attemps] inc)
:transport.inbox/request-messages {:web3 web3 :transport.inbox/request-messages {:web3 web3
:wnode wnode :wnode wnode

View File

@ -20,7 +20,7 @@
[react/text {:style styles/text [react/text {:style styles/text
:on-press (when mailserver-error? :on-press (when mailserver-error?
#(re-frame/dispatch [:inbox.ui/reconnect-mailserver-pressed]))} #(re-frame/dispatch [:inbox.ui/reconnect-mailserver-pressed]))}
(if fetching? (if (and (not mailserver-error?) fetching?)
(i18n/label :t/fetching-messages {:requests-left (str fetching?)}) (i18n/label :t/fetching-messages {:requests-left (str fetching?)})
(i18n/label label))]])) (i18n/label label))]]))