fix: mark :albumize? true when rebuild message (#15286)

This commit is contained in:
yqrashawn 2023-03-17 16:25:48 +08:00 committed by GitHub
parent 0e36190516
commit 2e0fa29806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 24 deletions

View File

@ -1,9 +1,9 @@
(ns status-im.chat.models.loading
(:require [re-frame.core :as re-frame]
[status-im2.contexts.chat.messages.list.events :as message-list]
[status-im2.constants :as constants]
[status-im.data-store.chats :as data-store.chats]
[status-im.data-store.messages :as data-store.messages]
[status-im2.constants :as constants]
[status-im2.contexts.chat.messages.list.events :as message-list]
[taoensso.timbre :as log]
[utils.re-frame :as rf]))
@ -100,17 +100,6 @@
:on-success #(re-frame/dispatch
[::mark-all-read-in-community-successful %])}]}))
;; For example, when a user receives a list of 4 image messages while inside the chat screen we
;; shouldn't group the images into albums. When the user exists the chat screen then enters the
;; chat screen again, we now need to group the images into albums (like WhatsApp). The albumize?
;; boolean is used to know whether we need to group these images into albums now or not. The
;; album-id can't be used for this because it will always be there.
(defn mark-album
[message]
(if (:album-id message)
(assoc message :albumize? true)
message))
(rf/defn messages-loaded
"Loads more messages for current chat"
{:events [::messages-loaded]}
@ -124,6 +113,16 @@
(reduce (fn [{:keys [all-messages] :as acc}
{:keys [message-id from]
:as message}]
(let [message
;; For example, when a user receives a list of 4 image messages while inside
;; the chat screen we shouldn't group the images into albums. When the user
;; exists the chat screen then enters the chat screen again, we now need to
;; group the images into albums (like WhatsApp). The albumize? boolean is used
;; to know whether we need to group these images into albums now or not. The
;; album-id can't be used for this because it will always be there.
(if (and (:album-id message) (nil? (get all-messages message-id)))
(assoc message :albumize? true)
message)]
(cond-> acc
(not (get-in db [:chats chat-id :users from]))
(update :senders assoc from message)
@ -132,7 +131,7 @@
(update :new-messages conj message)
:always
(update :all-messages assoc message-id message)))
(update :all-messages assoc message-id message))))
{:all-messages already-loaded-messages
:senders {}
:contacts {}
@ -141,8 +140,7 @@
current-clock-value (get-in db
[:pagination-info chat-id
:cursor-clock-value])
clock-value (when cursor (cursor->clock-value cursor))
new-messages (map mark-album new-messages)]
clock-value (when cursor (cursor->clock-value cursor))]
{:db (-> db
(update-in [:pagination-info chat-id :cursor-clock-value]
#(if (and (seq cursor) (or (not %) (< clock-value %)))

View File

@ -1,8 +1,8 @@
(ns status-im2.contexts.chat.messages.list.events
(:require [utils.red-black-tree :as red-black-tree]
(:require [status-im2.constants :as constants]
[utils.datetime :as datetime]
[utils.re-frame :as rf]
[status-im2.constants :as constants]))
[utils.red-black-tree :as red-black-tree]))
(defn- add-datemark
[{:keys [whisper-timestamp] :as msg}]