mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-27 17:06:18 +00:00
Adjust from value to accomodate for late-comers
Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
parent
fdb808a7dc
commit
8be8f0b5c8
@ -11,6 +11,7 @@
|
|||||||
[status-im.utils.utils :as utils]
|
[status-im.utils.utils :as utils]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
[status-im.transport.db :as transport.db]
|
[status-im.transport.db :as transport.db]
|
||||||
|
[status-im.transport.message.protocol :as protocol]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[status-im.data-store.mailservers :as data-store.mailservers]
|
[status-im.data-store.mailservers :as data-store.mailservers]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
@ -236,26 +237,41 @@
|
|||||||
|
|
||||||
(def limit 200)
|
(def limit 200)
|
||||||
|
|
||||||
|
(defn adjust-request-for-transit-time
|
||||||
|
[from]
|
||||||
|
(let [ttl (:ttl protocol/whisper-opts)
|
||||||
|
whisper-tolerance (:whisper-drift-tolerance protocol/whisper-opts)
|
||||||
|
adjustment (+ whisper-tolerance ttl)
|
||||||
|
adjusted-from (- (max from adjustment) adjustment)]
|
||||||
|
(log/debug "Adjusting mailserver request" "from:" from "adjusted-from:" adjusted-from)
|
||||||
|
adjusted-from))
|
||||||
|
|
||||||
(defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics cursor to from]}]
|
(defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics cursor to from]}]
|
||||||
(log/info "mailserver: request-messages for: "
|
;; Add some room to from, unless we break day boundaries so that messages that have
|
||||||
" topics " topics
|
;; been received after the last request are also fetched
|
||||||
" from " from
|
(let [adjusted-from (adjust-request-for-transit-time from)
|
||||||
" cursor " cursor
|
actual-from (if (> (- to adjusted-from) one-day)
|
||||||
" limit " limit
|
from
|
||||||
" to " to)
|
adjusted-from)]
|
||||||
(.requestMessages (transport.utils/shh web3)
|
(log/info "mailserver: request-messages for: "
|
||||||
(clj->js {:topics topics
|
" topics " topics
|
||||||
:mailServerPeer address
|
" from " actual-from
|
||||||
:symKeyID sym-key-id
|
" cursor " cursor
|
||||||
:timeout request-timeout
|
" limit " limit
|
||||||
:limit limit
|
" to " to)
|
||||||
:cursor cursor
|
(.requestMessages (transport.utils/shh web3)
|
||||||
:from from
|
(clj->js {:topics topics
|
||||||
:to to})
|
:mailServerPeer address
|
||||||
(fn [error request-id]
|
:symKeyID sym-key-id
|
||||||
(if-not error
|
:timeout request-timeout
|
||||||
(log/info "mailserver: messages request success for topic " topics "from" from "to" to)
|
:limit limit
|
||||||
(log/error "mailserver: messages request error for topic " topics ": " error)))))
|
:cursor cursor
|
||||||
|
:from actual-from
|
||||||
|
:to to})
|
||||||
|
(fn [error request-id]
|
||||||
|
(if-not error
|
||||||
|
(log/info "mailserver: messages request success for topic " topics "from" from "to" to)
|
||||||
|
(log/error "mailserver: messages request error for topic " topics ": " error))))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:mailserver/request-messages
|
:mailserver/request-messages
|
||||||
|
@ -16,10 +16,13 @@
|
|||||||
(receive [this chat-id signature timestamp cofx] "Method producing all effects necessary for receiving the message record")
|
(receive [this chat-id signature timestamp cofx] "Method producing all effects necessary for receiving the message record")
|
||||||
(validate [this] "Method returning the message if it is valid or nil if it is not"))
|
(validate [this] "Method returning the message if it is valid or nil if it is not"))
|
||||||
|
|
||||||
(def ^:private whisper-opts
|
(def whisper-opts
|
||||||
{:ttl 10 ;; ttl of 10 sec
|
{;; time drift that is tolerated by whisper, in seconds
|
||||||
:powTarget config/pow-target
|
:whisper-drift-tolerance 10
|
||||||
:powTime config/pow-time})
|
;; ttl of 10 sec
|
||||||
|
:ttl 10
|
||||||
|
:powTarget config/pow-target
|
||||||
|
:powTime config/pow-time})
|
||||||
|
|
||||||
(fx/defn init-chat
|
(fx/defn init-chat
|
||||||
"Initialises chat on protocol layer.
|
"Initialises chat on protocol layer.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user