mirror of
https://github.com/status-im/status-react.git
synced 2025-01-25 18:29:37 +00:00
Dont query mailserver when from is greater than to
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
b9148cb782
commit
42509e8fb6
@ -100,28 +100,37 @@
|
|||||||
(def one-day (* 24 3600))
|
(def one-day (* 24 3600))
|
||||||
(def seven-days (* 7 one-day))
|
(def seven-days (* 7 one-day))
|
||||||
|
|
||||||
|
(defn request-inbox-messages-params [mailserver from to topics]
|
||||||
|
(let [days (conj
|
||||||
|
(into [] (range from to one-day))
|
||||||
|
to)
|
||||||
|
day-ranges (map vector days (drop 1 days))]
|
||||||
|
(for [topic topics
|
||||||
|
[current-from current-to] day-ranges]
|
||||||
|
{:topic topic
|
||||||
|
:mailServerPeer (:address mailserver)
|
||||||
|
:symKeyID (:sym-key-id mailserver)
|
||||||
|
:from current-from
|
||||||
|
:to current-to})))
|
||||||
|
|
||||||
(defn request-inbox-messages
|
(defn request-inbox-messages
|
||||||
[web3 wnode topics from to success-fn error-fn]
|
[web3 mailserver topics start-from end-to success-fn error-fn]
|
||||||
(loop [from from
|
(log/info "offline inbox: request-messages request for topics " topics " from " start-from " to " end-to)
|
||||||
current-to to]
|
(doseq [{:keys [topic] :as params} (request-inbox-messages-params
|
||||||
(let [current-to (if (> (- to from) one-day)
|
mailserver
|
||||||
(+ from one-day)
|
start-from
|
||||||
to)
|
end-to
|
||||||
opts (merge {:mailServerPeer (:address wnode)
|
topics)]
|
||||||
:symKeyID (:sym-key-id wnode)
|
(log/info "offline inbox: request-messages for: "
|
||||||
:from from
|
" topic " topic
|
||||||
:to current-to})]
|
" from " (:from params)
|
||||||
(log/info "offline inbox: request-messages request for topics " topics " from " from " to " current-to)
|
" to " (:to params))
|
||||||
(doseq [topic topics]
|
(.requestMessages (transport.utils/shh web3)
|
||||||
(let [opts (assoc opts :topic topic)]
|
(clj->js params)
|
||||||
(.requestMessages (transport.utils/shh web3)
|
(fn [err resp]
|
||||||
(clj->js opts)
|
(if-not err
|
||||||
(fn [err resp]
|
(success-fn resp topic)
|
||||||
(if-not err
|
(error-fn err topic))))))
|
||||||
(success-fn resp topic)
|
|
||||||
(error-fn err topic))))))
|
|
||||||
(when (< current-to to)
|
|
||||||
(recur current-to to)))))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::add-peer
|
::add-peer
|
||||||
|
@ -103,3 +103,59 @@
|
|||||||
(testing "inbox is not ready"
|
(testing "inbox is not ready"
|
||||||
(testing "it does not do anything"
|
(testing "it does not do anything"
|
||||||
(is (nil? (inbox/request-messages {})))))))
|
(is (nil? (inbox/request-messages {})))))))
|
||||||
|
|
||||||
|
(deftest request-messages-params
|
||||||
|
(let [mailserver {:address "peer"
|
||||||
|
:sym-key-id "id"}]
|
||||||
|
(testing "from is greater that to"
|
||||||
|
(testing "it returns an empty sequence"
|
||||||
|
(is (empty? (inbox/request-inbox-messages-params mailserver 2 0 ["a" "b" "c"])))))
|
||||||
|
(testing "from is equal to to"
|
||||||
|
(testing "it returns an empty sequence"
|
||||||
|
(is (empty? (inbox/request-inbox-messages-params mailserver 2 2 ["a" "b" "c"])))))
|
||||||
|
(testing "to is less than the step"
|
||||||
|
(is (= #{{:topic "a"
|
||||||
|
:mailServerPeer "peer"
|
||||||
|
:symKeyID "id"
|
||||||
|
:from 0
|
||||||
|
:to 3}
|
||||||
|
{:topic "b"
|
||||||
|
:mailServerPeer "peer"
|
||||||
|
:symKeyID "id"
|
||||||
|
:from 0
|
||||||
|
:to 3}}
|
||||||
|
(into #{} (inbox/request-inbox-messages-params mailserver 0 3 ["a" "b"])))))
|
||||||
|
(testing "to is equal the step"
|
||||||
|
(is (= #{{:topic "a"
|
||||||
|
:mailServerPeer "peer"
|
||||||
|
:symKeyID "id"
|
||||||
|
:from 0
|
||||||
|
:to 86400}
|
||||||
|
{:topic "b"
|
||||||
|
:mailServerPeer "peer"
|
||||||
|
:symKeyID "id"
|
||||||
|
:from 0
|
||||||
|
:to 86400}}
|
||||||
|
(into #{} (inbox/request-inbox-messages-params mailserver 0 86400 ["a" "b"])))))
|
||||||
|
(testing "to is greather than the step"
|
||||||
|
(is (= #{{:topic "a"
|
||||||
|
:mailServerPeer "peer"
|
||||||
|
:symKeyID "id"
|
||||||
|
:from 0
|
||||||
|
:to 86400}
|
||||||
|
{:topic "b"
|
||||||
|
:mailServerPeer "peer"
|
||||||
|
:symKeyID "id"
|
||||||
|
:from 0
|
||||||
|
:to 86400}
|
||||||
|
{:topic "a"
|
||||||
|
:mailServerPeer "peer"
|
||||||
|
:symKeyID "id"
|
||||||
|
:from 86400
|
||||||
|
:to 90000}
|
||||||
|
{:topic "b"
|
||||||
|
:mailServerPeer "peer"
|
||||||
|
:symKeyID "id"
|
||||||
|
:from 86400
|
||||||
|
:to 90000}}
|
||||||
|
(into #{} (inbox/request-inbox-messages-params mailserver 0 90000 ["a" "b"])))))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user