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.data-store.transport :as transport-store]))
(defn receive-message [cofx chat-id js-message]
(let [{:keys [payload sig]} (js->clj js-message :keywordize-keys true)
(defn update-last-received-from-inbox
"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
transport.utils/to-utf8
transit/deserialize
(assoc :js-obj js-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]
(for [i (range (.-length array))]
(aget array i)))
(defn receive-whisper-messages [cofx [js-error js-messages chat-id]]
(handlers-macro/merge-effects
cofx
(fn [message temp-cofx]
(receive-message temp-cofx chat-id message))
(js-array->list js-messages)))
(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
cofx
(fn [message temp-cofx]
(receive-message temp-cofx now-in-s chat-id message))
(js-array->list js-messages))))
(handlers/register-handler-fx
:protocol/receive-whisper-message

View File

@ -179,6 +179,7 @@
:inbox/password
:inbox/sym-key-id
:inbox/last-request
:inbox/last-received
:inbox/fetching?
:browser/browsers
: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/sym-key-id string?)
(spec/def :inbox/last-request integer?)
(spec/def :inbox/last-received integer?)