Fix counter when message is updated (#1023)

This commit is contained in:
Stanislav Dmitrenko
2022-09-06 22:26:52 +03:00
committed by GitHub
parent 03b4bea82a
commit 65f3fe8afc

View File

@@ -163,6 +163,10 @@ class ChatModel(val controller: ChatController) {
val pItem = chat.chatItems.lastOrNull()
if (pItem?.id == cItem.id) {
chats[i] = chat.copy(chatItems = arrayListOf(cItem))
if (pItem.isRcvNew && !cItem.isRcvNew) {
// status changed from New to Read, update counter
decreaseCounterInChat(cInfo.id)
}
}
res = false
} else {
@@ -251,6 +255,18 @@ class ChatModel(val controller: ChatController) {
return markedRead
}
private fun decreaseCounterInChat(chatId: ChatId) {
val chatIndex = getChatIndex(chatId)
if (chatIndex == -1) return
val chat = chats[chatIndex]
chats[chatIndex] = chat.copy(
chatStats = chat.chatStats.copy(
unreadCount = kotlin.math.max(chat.chatStats.unreadCount - 1, 0),
)
)
}
// func popChat(_ id: String) {
// if let i = getChatIndex(id) {
// popChat_(i)