From 7a488b92a224ae353a51570e0971f1101eb8003e Mon Sep 17 00:00:00 2001 From: over140 Date: Fri, 28 Feb 2025 11:21:14 +0400 Subject: [PATCH] Try to fix incorrect unread message count in conversation. --- .../Services/WebSocket/Service/SendMessageService.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MixinServices/MixinServices/Services/WebSocket/Service/SendMessageService.swift b/MixinServices/MixinServices/Services/WebSocket/Service/SendMessageService.swift index 30379b231c..6a43534063 100644 --- a/MixinServices/MixinServices/Services/WebSocket/Service/SendMessageService.swift +++ b/MixinServices/MixinServices/Services/WebSocket/Service/SendMessageService.swift @@ -218,6 +218,14 @@ public class SendMessageService: MixinService { let unreadMessages = MessageDAO.shared.getUnreadMessages(conversationId: conversationId) var position = 0 let pageCount = AppGroupUserDefaults.Account.isDesktopLoggedIn ? 1000 : 2000 + if unreadMessages.count == 0 { + UserDatabase.current.write { (db) in + let unseenMessageCountSQL = "SELECT unseen_message_count FROM \(Conversation.databaseTableName) WHERE conversation_id = ?" + if let unseenMessageCount = try Int.fetchOne(db, sql: unseenMessageCountSQL, arguments: [conversationId]), unseenMessageCount > 0 { + try MessageDAO.shared.updateUnseenMessageCount(database: db, conversationId: conversationId) + } + } + } while unreadMessages.count > 0 && position < unreadMessages.count { let nextPosition = position + pageCount > unreadMessages.count ? unreadMessages.count : position + pageCount let messages = Array(unreadMessages[position..