From 68cb9258c5d9a636925e05ec6b4f1d51d1c92fd4 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 1 Nov 2019 19:26:32 -0500 Subject: [PATCH] Clean up deleted and inactive accounts from Smartfeeds. Issue #1205 --- Shared/SmartFeeds/SmartFeed.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 {