[Fixes: #12448] Fix unread indicator in chat on message delete
This commit is contained in:
parent
31e6649cd4
commit
a569687161
|
@ -431,3 +431,13 @@
|
|||
:on-accept #(do
|
||||
(re-frame/dispatch [:bottom-sheet/hide])
|
||||
(re-frame/dispatch [:chat.ui/remove-chat chat-id]))}})
|
||||
|
||||
(fx/defn decrease-unviewed-count
|
||||
{:events [:chat/decrease-unviewed-count]}
|
||||
[{:keys [db]} chat-id unseen-messages]
|
||||
{:db (update-in db [:chats chat-id :unviewed-messages-count]
|
||||
(fn [count]
|
||||
;; There might be some other requests being fired,
|
||||
;; so we need to make sure the count has not been set to
|
||||
;; 0 in the meantime
|
||||
(max (- count unseen-messages) 0)))})
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
(ns status-im.chat.models.message
|
||||
(:require [status-im.chat.models :as chat-model]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.chat.models.message-list :as message-list]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.data-store.messages :as data-store.messages]
|
||||
|
@ -195,29 +196,21 @@
|
|||
[cofx messages]
|
||||
(protocol/send-chat-messages cofx messages))
|
||||
|
||||
(defn flip-args [f]
|
||||
(fn [x y] (f y x)))
|
||||
|
||||
(defn message-ids->message-id-chat-id-map
|
||||
"Determine the chat ids of a seq of message-ids"
|
||||
[db message-ids]
|
||||
(->> db
|
||||
:messages ; get messages map
|
||||
seq ; convert it to seq
|
||||
(map second) ; get values of messages map -> message-id : message-obj
|
||||
(into {}) ; convert message-id : message-obj seq to map
|
||||
((flip-args select-keys) message-ids) ; select the message objects of the ids in question
|
||||
vals ; keep only the values of required messages
|
||||
(map #(select-keys % [:chat-id :message-id])))) ; return the chat-id and message-id of required messages
|
||||
|
||||
(fx/defn handle-removed-messages
|
||||
{:events [::handle-removed-messages]}
|
||||
[{:keys [db]} removed-messages]
|
||||
(let [mcids (message-ids->message-id-chat-id-map db removed-messages)]
|
||||
{:db (reduce (fn [acc current]
|
||||
(update-in acc [:messages (:chat-id current)] dissoc (:message-id current)))
|
||||
db mcids)
|
||||
:dispatch [:get-activity-center-notifications]}))
|
||||
[{:keys [db] :as cofx} removed-messages]
|
||||
(let [mark-as-seen-fx (mapv (fn [removed-message]
|
||||
(let [chat-id (:chatId removed-message)
|
||||
message-id (:messageId removed-message)]
|
||||
(data-store.messages/mark-messages-seen chat-id
|
||||
[message-id]
|
||||
#(re-frame/dispatch [:chat/decrease-unviewed-count chat-id %3])))) removed-messages)
|
||||
remove-messages-fx (fn [{:keys [db]}]
|
||||
{:db (reduce (fn [acc current]
|
||||
(update-in acc [:messages (:chatId current)] dissoc (:messageId current)))
|
||||
db removed-messages)
|
||||
:dispatch [:get-activity-center-notifications]})]
|
||||
(apply fx/merge cofx (conj mark-as-seen-fx remove-messages-fx))))
|
||||
|
||||
(comment
|
||||
(handle-removed-messages
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
(ns status-im.chat.models.message-seen
|
||||
(:require [status-im.utils.fx :as fx]
|
||||
[status-im.data-store.messages :as messages-store]))
|
||||
|
||||
(defn subtract-seen-messages
|
||||
[old-count new-seen-messages-ids]
|
||||
(max 0 (- old-count (count new-seen-messages-ids))))
|
||||
|
||||
(fx/defn update-chats-unviewed-messages-count
|
||||
[{:keys [db]} {:keys [chat-id _]}]
|
||||
(let [{:keys [loaded-unviewed-messages-ids unviewed-messages-count]}
|
||||
(get-in db [:chats chat-id])]
|
||||
;; We currently only use this for private group chats and one-to-ones
|
||||
;; but this method would have to be changed if we showed unviewed-mentions-count
|
||||
;; in one to ones and private group chats as well
|
||||
{:db (update-in db [:chats chat-id] assoc
|
||||
:unviewed-messages-count (subtract-seen-messages
|
||||
unviewed-messages-count
|
||||
loaded-unviewed-messages-ids))}))
|
||||
|
||||
(fx/defn mark-messages-seen
|
||||
"Marks all unviewed loaded messages as seen in particular chat"
|
||||
[{:keys [db] :as cofx} chat-id]
|
||||
(let [loaded-unviewed-ids (get-in db [:chats chat-id :loaded-unviewed-messages-ids])]
|
||||
(when (seq loaded-unviewed-ids)
|
||||
(fx/merge cofx
|
||||
{:db (reduce (fn [acc message-id]
|
||||
(assoc-in acc [:messages chat-id message-id :seen]
|
||||
true))
|
||||
db
|
||||
loaded-unviewed-ids)}
|
||||
(messages-store/mark-messages-seen chat-id loaded-unviewed-ids nil)
|
||||
(update-chats-unviewed-messages-count {:chat-id chat-id})))))
|
|
@ -2,7 +2,7 @@
|
|||
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
|
||||
"owner": "status-im",
|
||||
"repo": "status-go",
|
||||
"version": "v0.83.18",
|
||||
"commit-sha1": "0e54d04e67fee94276b69a9b20338cf4e7624cc5",
|
||||
"src-sha256": "091g3xqsswvfi58jnr9xcwx8xhzcch7d5yky00gjxmw70hyxwigw"
|
||||
"version": "v0.84.1",
|
||||
"commit-sha1": "83394e0ed17265cb20ab3e56fe3de13ca4057267",
|
||||
"src-sha256": "0xhg4n5i8ifv2z3vydi0878n6mv53cajmsr54fpaxqr4lvhrkzza"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue