From 40df57a2172a6ce15849c682476e61713f696a49 Mon Sep 17 00:00:00 2001 From: Ambroise Decouttere Date: Thu, 5 Jan 2023 14:29:38 +0100 Subject: [PATCH 1/3] fix: UnreadCount --- MailCore/Models/Folder.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MailCore/Models/Folder.swift b/MailCore/Models/Folder.swift index 380463a15..dfc45a1dd 100644 --- a/MailCore/Models/Folder.swift +++ b/MailCore/Models/Folder.swift @@ -178,8 +178,7 @@ public class Folder: Object, Codable, Comparable, Identifiable { } public func computeUnreadCount(using realm: Realm) { - let unreadMessages = realm.objects(Message.self).where { $0.folderId == self.id && $0.seen == false } - unreadCount = unreadMessages.count + unreadCount = threads.where { $0.hasUnseenMessages == true }.count } public func isParent(of folder: Folder) -> Bool { From 5e02401da72b60f4887dc6d6846c38485158f89b Mon Sep 17 00:00:00 2001 From: Ambroise Decouttere Date: Thu, 5 Jan 2023 19:03:13 +0100 Subject: [PATCH 2/3] fix: Remove useless Realm parameter --- MailCore/Cache/MailboxManager.swift | 2 +- MailCore/Models/Folder.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MailCore/Cache/MailboxManager.swift b/MailCore/Cache/MailboxManager.swift index 8f9f050dd..6191956b1 100644 --- a/MailCore/Cache/MailboxManager.swift +++ b/MailCore/Cache/MailboxManager.swift @@ -652,7 +652,7 @@ public class MailboxManager: ObservableObject { if newCursor != nil { guard let folder = folder.fresh(using: realm) else { return } try? realm.safeWrite { - folder.computeUnreadCount(using: realm) + folder.computeUnreadCount() folder.cursor = newCursor folder.lastUpdate = Date() } diff --git a/MailCore/Models/Folder.swift b/MailCore/Models/Folder.swift index dfc45a1dd..f3750a829 100644 --- a/MailCore/Models/Folder.swift +++ b/MailCore/Models/Folder.swift @@ -177,7 +177,7 @@ public class Folder: Object, Codable, Comparable, Identifiable { return lhs.id == rhs.id } - public func computeUnreadCount(using realm: Realm) { + public func computeUnreadCount() { unreadCount = threads.where { $0.hasUnseenMessages == true }.count } From b57008186a4dcc1a96d6b94e524b1027eeb3a063 Mon Sep 17 00:00:00 2001 From: Ambroise Decouttere Date: Fri, 6 Jan 2023 09:50:18 +0100 Subject: [PATCH 3/3] fix: unreadCountBadge --- MailCore/Utils/NotificationsHelper.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/MailCore/Utils/NotificationsHelper.swift b/MailCore/Utils/NotificationsHelper.swift index 91d682163..edc848104 100644 --- a/MailCore/Utils/NotificationsHelper.swift +++ b/MailCore/Utils/NotificationsHelper.swift @@ -64,10 +64,8 @@ public enum NotificationsHelper { for mailbox in MailboxInfosManager.instance.getMailboxes() { if let mailboxManager = AccountManager.instance.getMailboxManager(for: mailbox), let inboxFolder = mailboxManager.getFolder(with: .inbox) { - totalUnreadCount += mailboxManager.getRealm() - .objects(Message.self) - .where { $0.seen == false && $0.folderId == inboxFolder.id } - .count + inboxFolder.computeUnreadCount() + totalUnreadCount += inboxFolder.unreadCount } }