dont show gaps in timeline/profile chats

This commit is contained in:
Andrea Maria Piana 2021-05-31 12:58:17 +02:00
parent 58d994706f
commit d6a999043e
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 14 additions and 4 deletions

View File

@ -61,7 +61,7 @@
"collapse-gaps will take an array of messages and collapse any gap next to "collapse-gaps will take an array of messages and collapse any gap next to
each other in a single gap. each other in a single gap.
It will also append one last gap if the last message is a non-gap" It will also append one last gap if the last message is a non-gap"
[messages chat-id synced-from] [messages chat-id synced-from chat-type]
(let [messages-with-gaps (reduce (let [messages-with-gaps (reduce
(fn [acc {:keys [gap-parameters message-id] :as message}] (fn [acc {:keys [gap-parameters message-id] :as message}]
(let [last-element (peek acc)] (let [last-element (peek acc)]
@ -83,6 +83,8 @@
messages)] messages)]
;; If it's a gap or the chat is still syncing, do nothing ;; If it's a gap or the chat is still syncing, do nothing
(if (or (nil? synced-from) (if (or (nil? synced-from)
(= constants/timeline-chat-type chat-type)
(= constants/profile-chat-type chat-type)
(:gap-ids (peek messages-with-gaps))) (:gap-ids (peek messages-with-gaps)))
messages-with-gaps messages-with-gaps
(conj messages-with-gaps (last-gap chat-id synced-from))))) (conj messages-with-gaps (last-gap chat-id synced-from)))))

View File

@ -780,6 +780,13 @@
(fn [{:keys [synced-from]}] (fn [{:keys [synced-from]}]
synced-from)) synced-from))
(re-frame/reg-sub
:chats/chat-type
(fn [[_ chat-id] _]
(re-frame/subscribe [:chat-by-id chat-id]))
(fn [{:keys [chat-type]}]
chat-type))
(re-frame/reg-sub (re-frame/reg-sub
:chats/synced-to-and-from :chats/synced-to-and-from
(fn [[_ chat-id] _] (fn [[_ chat-id] _]
@ -949,8 +956,9 @@
[(re-frame/subscribe [:chats/message-list chat-id]) [(re-frame/subscribe [:chats/message-list chat-id])
(re-frame/subscribe [:chats/chat-messages chat-id]) (re-frame/subscribe [:chats/chat-messages chat-id])
(re-frame/subscribe [:chats/loading-messages? chat-id]) (re-frame/subscribe [:chats/loading-messages? chat-id])
(re-frame/subscribe [:chats/synced-from chat-id])]) (re-frame/subscribe [:chats/synced-from chat-id])
(fn [[message-list messages loading-messages? synced-from] [_ chat-id]] (re-frame/subscribe [:chats/chat-type chat-id])])
(fn [[message-list messages loading-messages? synced-from chat-type] [_ chat-id]]
;;TODO (perf) ;;TODO (perf)
(let [message-list-seq (models.message-list/->seq message-list)] (let [message-list-seq (models.message-list/->seq message-list)]
; Don't show gaps if that's the case as we are still loading messages ; Don't show gaps if that's the case as we are still loading messages
@ -959,7 +967,7 @@
(-> message-list-seq (-> message-list-seq
(chat.db/add-datemarks) (chat.db/add-datemarks)
(hydrate-messages messages) (hydrate-messages messages)
(chat.db/collapse-gaps chat-id synced-from)))))) (chat.db/collapse-gaps chat-id synced-from chat-type))))))
;;we want to keep data unchanged so react doesn't change component when we leave screen ;;we want to keep data unchanged so react doesn't change component when we leave screen
(def memo-chat-messages-stream (atom nil)) (def memo-chat-messages-stream (atom nil))