android, desktop: marking chat read fix (#5658)

* android, desktop: marking chat read fix

* comments
This commit is contained in:
Stanislav Dmitrenko 2025-02-24 14:50:30 +07:00 committed by GitHub
parent 41ccb14bfa
commit c81fa7e6b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 3 deletions

View file

@ -1612,6 +1612,7 @@ public struct ChatStats: Decodable, Hashable {
// actual only via getChats() and getChat(.initial), otherwise, zero
public var reportsCount: Int = 0
public var minUnreadItemId: Int64 = 0
// actual only via getChats(), otherwise, false
public var unreadChat: Bool = false
}

View file

@ -1233,10 +1233,11 @@ data class Chat(
@Serializable
data class ChatStats(
val unreadCount: Int = 0,
// actual only via getChats() and getChat(.initial), otherwise, zero
val unreadMentions: Int = 0,
// actual only via getChats() and getChat(.initial), otherwise, zero
val reportsCount: Int = 0,
val minUnreadItemId: Long = 0,
// actual only via getChats(), otherwise, false
val unreadChat: Boolean = false
)

View file

@ -54,11 +54,13 @@ suspend fun processLoadedChat(
if (contentTag == null) {
// update main chats, not content tagged
withChats {
if (getChat(chat.id) == null) {
val oldChat = getChat(chat.id)
if (oldChat == null) {
addChat(chat)
} else {
updateChatInfo(chat.remoteHostId, chat.chatInfo)
updateChatStats(chat.remoteHostId, chat.id, chat.chatStats)
// unreadChat is currently not actual in getChat query (always false)
updateChatStats(chat.remoteHostId, chat.id, chat.chatStats.copy(unreadChat = oldChat.chatStats.unreadChat))
}
}
}