diff --git a/src/status_im/transport/inbox.cljs b/src/status_im/transport/inbox.cljs index 49b901f14b..d84e218245 100644 --- a/src/status_im/transport/inbox.cljs +++ b/src/status_im/transport/inbox.cljs @@ -260,8 +260,9 @@ (let [wnode (get-current-wnode db) web3 (:web3 db) now-in-s (quot now 1000) - last-request (get-in db [:account/account :last-request] - (- now-in-s seven-days)) + last-request (or + (get-in db [:account/account :last-request]) + (- now-in-s seven-days)) request-messages-topics (get-request-messages-topics db) request-history-topics (get-request-history-topics db)] (when (inbox-ready? wnode cofx) diff --git a/test/cljs/status_im/test/transport/inbox.cljs b/test/cljs/status_im/test/transport/inbox.cljs index 03d7265da2..a940cf363b 100644 --- a/test/cljs/status_im/test/transport/inbox.cljs +++ b/test/cljs/status_im/test/transport/inbox.cljs @@ -66,3 +66,33 @@ (testing "it does not generate a sym key if already present" (is (not (-> (inbox/connect-to-mailserver {:db wnode-with-sym-key-db}) :shh/generate-sym-key-from-password))))))) + +(deftest request-messages + (let [db {:network "mainnet" + :mailserver-status :connected + :inbox/wnodes + {:mainnet {"wnodeid" {:address "wnode-address" + :sym-key-id "something" + :password "wnode-password"}}} + :account/account + {:settings {:wnode {:mainnet "wnodeid"}} + :networks {"mainnet" {:config {:NetworkId 1}}}}} + cofx {:db db :now 1000000000}] + (testing "inbox is ready" + (testing "last-request is set" + (let [cofx-with-last-request (assoc-in cofx [:db :account/account :last-request] 2) + actual (inbox/request-messages cofx-with-last-request)] + (testing "it uses last request" + (is (= 2 (get-in actual [::inbox/request-messages :from])))))) + (testing "last-request is not set" + (let [actual (inbox/request-messages cofx)] + (testing "it defaults to the last 7 days" + (is (= 395200 (get-in actual [::inbox/request-messages :from])))))) + (testing "last-request is nil" + (let [cofx-with-last-request (assoc-in cofx [:db :account/account :last-request] nil) + actual (inbox/request-messages cofx-with-last-request)] + (testing "it defaults to the last 7 days" + (is (= 395200 (get-in actual [::inbox/request-messages :from]))))))) + (testing "inbox is not ready" + (testing "it does not do anything" + (is (nil? (inbox/request-messages {})))))))