Skip to content

Commit

Permalink
Merge pull request #469 from Infomaniak/unread-count
Browse files Browse the repository at this point in the history
fix: UnreadCount
  • Loading branch information
PhilippeWeidmann authored Jan 6, 2023
2 parents 0a21a64 + b570081 commit adf6276
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MailCore/Cache/MailboxManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
5 changes: 2 additions & 3 deletions MailCore/Models/Folder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ public class Folder: Object, Codable, Comparable, Identifiable {
return lhs.id == rhs.id
}

public func computeUnreadCount(using realm: Realm) {
let unreadMessages = realm.objects(Message.self).where { $0.folderId == self.id && $0.seen == false }
unreadCount = unreadMessages.count
public func computeUnreadCount() {
unreadCount = threads.where { $0.hasUnseenMessages == true }.count
}

public func isParent(of folder: Folder) -> Bool {
Expand Down
6 changes: 2 additions & 4 deletions MailCore/Utils/NotificationsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit adf6276

Please sign in to comment.