diff --git a/Shared/SmartFeeds/SmartFeed.swift b/Shared/SmartFeeds/SmartFeed.swift index 9a9b3e677..888c6ab01 100644 --- a/Shared/SmartFeeds/SmartFeed.swift +++ b/Shared/SmartFeeds/SmartFeed.swift @@ -51,8 +51,23 @@ final class SmartFeed: PseudoFeed { } @objc func fetchUnreadCounts() { - AccountManager.shared.activeAccounts.forEach { self.fetchUnreadCount(for: $0) } + let activeAccounts = AccountManager.shared.activeAccounts + + // Remove any accounts that are no longer active or have been deleted + let activeAccountIDs = activeAccounts.map { $0.accountID } + unreadCounts.keys.forEach { accountID in + if !activeAccountIDs.contains(accountID) { + unreadCounts.removeValue(forKey: accountID) + } + } + + if activeAccounts.isEmpty { + updateUnreadCount() + } else { + activeAccounts.forEach { self.fetchUnreadCount(for: $0) } + } } + } extension SmartFeed: ArticleFetcher {