Update last-received everytime a message is received from inbox

This commit is contained in:
Eric Dvorsak 2018-05-27 17:34:50 +02:00
parent 5b5a5f72ec
commit 3430bfe61e
No known key found for this signature in database
GPG Key ID: 932AC1CE5F05DE0C
3 changed files with 22 additions and 9 deletions

View File

@ -18,25 +18,36 @@
[status-im.transport.message.v1.group-chat :as v1.group-chat] [status-im.transport.message.v1.group-chat :as v1.group-chat]
[status-im.data-store.transport :as transport-store])) [status-im.data-store.transport :as transport-store]))
(defn receive-message [cofx chat-id js-message] (defn update-last-received-from-inbox
(let [{:keys [payload sig]} (js->clj js-message :keywordize-keys true) "Distinguishes messages that are expired from those that are not
Expired messages are coming from offline inboxing"
[now-in-s timestamp ttl {:keys [db now] :as cofx}]
(when (> (- now-in-s timestamp) ttl)
{:db (assoc db :inbox/last-received now)}))
(defn receive-message [cofx now-in-s chat-id js-message]
(let [{:keys [payload sig timestamp ttl]} (js->clj js-message :keywordize-keys true)
status-message (-> payload status-message (-> payload
transport.utils/to-utf8 transport.utils/to-utf8
transit/deserialize transit/deserialize
(assoc :js-obj js-message))] (assoc :js-obj js-message))]
(when (and sig status-message) (when (and sig status-message)
(message/receive status-message (or chat-id sig) sig cofx)))) (handlers-macro/merge-fx
cofx
(message/receive status-message (or chat-id sig) sig)
(update-last-received-from-inbox now-in-s timestamp ttl)))))
(defn- js-array->list [array] (defn- js-array->list [array]
(for [i (range (.-length array))] (for [i (range (.-length array))]
(aget array i))) (aget array i)))
(defn receive-whisper-messages [cofx [js-error js-messages chat-id]] (defn receive-whisper-messages [{:keys [now] :as cofx} [js-error js-messages chat-id]]
(let [now-in-s (quot now 1000)]
(handlers-macro/merge-effects (handlers-macro/merge-effects
cofx cofx
(fn [message temp-cofx] (fn [message temp-cofx]
(receive-message temp-cofx chat-id message)) (receive-message temp-cofx now-in-s chat-id message))
(js-array->list js-messages))) (js-array->list js-messages))))
(handlers/register-handler-fx (handlers/register-handler-fx
:protocol/receive-whisper-message :protocol/receive-whisper-message

View File

@ -179,6 +179,7 @@
:inbox/password :inbox/password
:inbox/sym-key-id :inbox/sym-key-id
:inbox/last-request :inbox/last-request
:inbox/last-received
:inbox/fetching? :inbox/fetching?
:browser/browsers :browser/browsers
:browser/options :browser/options

View File

@ -18,3 +18,4 @@
(spec/def :inbox/wnodes (spec/nilable (spec/map-of keyword? (spec/map-of :wnode/id :wnode/wnode)))) (spec/def :inbox/wnodes (spec/nilable (spec/map-of keyword? (spec/map-of :wnode/id :wnode/wnode))))
(spec/def :inbox/sym-key-id string?) (spec/def :inbox/sym-key-id string?)
(spec/def :inbox/last-request integer?) (spec/def :inbox/last-request integer?)
(spec/def :inbox/last-received integer?)