Use cursor and update status-go

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2018-12-13 12:23:16 +01:00
parent 6e5d54b5aa
commit 05b70b0974
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 28 additions and 13 deletions

View File

@ -1 +1 @@
0.17.8-beta 0.17.9-beta

View File

@ -234,16 +234,22 @@
mailserver-removed? mailserver-removed?
(connect-to-mailserver cofx))))) (connect-to-mailserver cofx)))))
(defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics to from]}] (def limit 200)
(defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics cursor to from]}]
(log/info "mailserver: request-messages for: " (log/info "mailserver: request-messages for: "
" topics " topics " topics " topics
" from " from " from " from
" cursor " cursor
" limit " limit
" to " to) " to " to)
(.requestMessages (transport.utils/shh web3) (.requestMessages (transport.utils/shh web3)
(clj->js {:topics topics (clj->js {:topics topics
:mailServerPeer address :mailServerPeer address
:symKeyID sym-key-id :symKeyID sym-key-id
:timeout request-timeout :timeout request-timeout
:limit limit
:cursor cursor
:from from :from from
:to to}) :to to})
(fn [error request-id] (fn [error request-id]
@ -409,7 +415,7 @@
(fx/defn update-mailserver-topics (fx/defn update-mailserver-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]}] [{:keys [db now] :as cofx} {:keys [request-id cursor]}]
(when-let [request (get db :mailserver/current-request)] (when-let [request (get db :mailserver/current-request)]
(let [{:keys [from to topics]} request (let [{:keys [from to topics]} request
mailserver-topics (get-updated-mailserver-topics db topics to)] mailserver-topics (get-updated-mailserver-topics db topics to)]
@ -420,6 +426,13 @@
(fx/merge cofx (fx/merge cofx
{:db (dissoc db :mailserver/current-request)} {:db (dissoc db :mailserver/current-request)}
(process-next-messages-request)) (process-next-messages-request))
;; If a cursor is returned, add cursor and fire request again
(if (seq cursor)
(when-let [mailserver (get-mailserver-when-ready cofx)]
{:mailserver/request-messages {:web3 (:web3 db)
:mailserver mailserver
:request (assoc request :cursor cursor)}})
(fx/merge cofx (fx/merge cofx
{:db (-> db {:db (-> db
(dissoc :mailserver/current-request) (dissoc :mailserver/current-request)
@ -429,7 +442,7 @@
{:topic topic {:topic topic
:mailserver-topic mailserver-topic})) :mailserver-topic mailserver-topic}))
mailserver-topics)} mailserver-topics)}
(process-next-messages-request)))))) (process-next-messages-request)))))))
(fx/defn retry-next-messages-request (fx/defn retry-next-messages-request
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
@ -437,6 +450,8 @@
{:db (dissoc db :mailserver/request-error)} {:db (dissoc db :mailserver/request-error)}
(process-next-messages-request))) (process-next-messages-request)))
;; At some point we should update `last-request`, as eventually we want to move
;; on, rather then keep asking for the same data, say after n amounts of attempts
(fx/defn handle-request-error (fx/defn handle-request-error
[{:keys [db]} error] [{:keys [db]} error]
{:db (-> db {:db (-> db