mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 03:26:31 +00:00
Ensure valid timestamp for all messages
This commit is contained in:
parent
e3d86beab2
commit
0ad15a79d6
@ -124,8 +124,8 @@
|
|||||||
(transport/send (protocol/map->MessagesSeen {:message-ids #{message-id}}) chat-id cofx)))
|
(transport/send (protocol/map->MessagesSeen {:message-ids #{message-id}}) chat-id cofx)))
|
||||||
|
|
||||||
(defn- add-received-message
|
(defn- add-received-message
|
||||||
[batch?
|
[batch?
|
||||||
{:keys [from message-id chat-id content content-type timestamp clock-value to-clock-value js-obj] :as message}
|
{:keys [from message-id chat-id content content-type clock-value to-clock-value js-obj] :as message}
|
||||||
{:keys [db now] :as cofx}]
|
{:keys [db now] :as cofx}]
|
||||||
(let [{:keys [web3 current-chat-id view-id access-scope->commands-responses]
|
(let [{:keys [web3 current-chat-id view-id access-scope->commands-responses]
|
||||||
:contacts/keys [contacts]} db
|
:contacts/keys [contacts]} db
|
||||||
@ -158,6 +158,9 @@
|
|||||||
(def ^:private add-single-received-message (partial add-received-message false))
|
(def ^:private add-single-received-message (partial add-received-message false))
|
||||||
(def ^:private add-batch-received-message (partial add-received-message true))
|
(def ^:private add-batch-received-message (partial add-received-message true))
|
||||||
|
|
||||||
|
(defn ensure-timestamp [now message]
|
||||||
|
(update message :timestamp (fnil identity now)))
|
||||||
|
|
||||||
(defn receive
|
(defn receive
|
||||||
[{:keys [chat-id message-id] :as message} {:keys [now] :as cofx}]
|
[{:keys [chat-id message-id] :as message} {:keys [now] :as cofx}]
|
||||||
(handlers-macro/merge-fx cofx
|
(handlers-macro/merge-fx cofx
|
||||||
@ -165,11 +168,11 @@
|
|||||||
;; We activate a chat again on new messages
|
;; We activate a chat again on new messages
|
||||||
:is-active true
|
:is-active true
|
||||||
:timestamp now})
|
:timestamp now})
|
||||||
(add-single-received-message message)))
|
(add-single-received-message (ensure-timestamp now message))))
|
||||||
|
|
||||||
(defn receive-many
|
(defn receive-many
|
||||||
[messages {:keys [now] :as cofx}]
|
[raw-messages {:keys [now] :as cofx}]
|
||||||
(let [chat-ids (into #{} (map :chat-id) messages)
|
(let [chat-ids (into #{} (map :chat-id) raw-messages)
|
||||||
chat-effects (handlers-macro/merge-effects cofx
|
chat-effects (handlers-macro/merge-effects cofx
|
||||||
(fn [chat-id cofx]
|
(fn [chat-id cofx]
|
||||||
(chat-model/upsert-chat {:chat-id chat-id
|
(chat-model/upsert-chat {:chat-id chat-id
|
||||||
@ -177,6 +180,7 @@
|
|||||||
:timestamp now}
|
:timestamp now}
|
||||||
cofx))
|
cofx))
|
||||||
chat-ids)
|
chat-ids)
|
||||||
|
messages (map (partial ensure-timestamp now) raw-messages)
|
||||||
message-effects (handlers-macro/merge-effects chat-effects cofx add-batch-received-message messages)]
|
message-effects (handlers-macro/merge-effects chat-effects cofx add-batch-received-message messages)]
|
||||||
(handlers-macro/merge-effects message-effects
|
(handlers-macro/merge-effects message-effects
|
||||||
cofx
|
cofx
|
||||||
|
@ -97,21 +97,27 @@
|
|||||||
:content "d"
|
:content "d"
|
||||||
:clock-value 3
|
:clock-value 3
|
||||||
:timestamp 3}}}}}}
|
:timestamp 3}}}}}}
|
||||||
new-messages '({:message-id 1
|
new-messages [{:message-id 1
|
||||||
:content "b"
|
:content "b"
|
||||||
:clock-value 1
|
:clock-value 1
|
||||||
:timestamp 1
|
:timestamp 1
|
||||||
:show? false}
|
:show? false}
|
||||||
{:message-id 2
|
;; TODO(janherich) : rewrite this so `receive-many` is
|
||||||
:content "c"
|
;; tested instead
|
||||||
:clock-value 2
|
;; dont' owerwrite existing timestamp
|
||||||
:timestamp 2
|
(message/ensure-timestamp 4
|
||||||
:show? true}
|
{:message-id 2
|
||||||
{:message-id 3
|
:content "c"
|
||||||
:content "d"
|
:clock-value 2
|
||||||
:clock-value 3
|
:timestamp 2
|
||||||
:timestamp 3
|
:show? true})
|
||||||
:show? true})]
|
;; provide timestmap if not present
|
||||||
|
(message/ensure-timestamp 3
|
||||||
|
{:message-id 3
|
||||||
|
:content "d"
|
||||||
|
:clock-value 3
|
||||||
|
:timestamp 3
|
||||||
|
:show? true})]]
|
||||||
(testing "New messages are grouped/sorted correctly, hidden messages are not grouped"
|
(testing "New messages are grouped/sorted correctly, hidden messages are not grouped"
|
||||||
(is (= '(2 3)
|
(is (= '(2 3)
|
||||||
(map :message-id
|
(map :message-id
|
||||||
|
Loading…
x
Reference in New Issue
Block a user