diff --git a/Frameworks/Account/AccountManager.swift b/Frameworks/Account/AccountManager.swift index e70ae561f..9b7dbbf35 100644 --- a/Frameworks/Account/AccountManager.swift +++ b/Frameworks/Account/AccountManager.swift @@ -25,7 +25,7 @@ public final class AccountManager: UnreadCountProvider { private var accountsDictionary = [String: Account]() public var isUnreadCountsInitialized: Bool { - for account in accounts { + for account in activeAccounts { if !account.isUnreadCountsInitialized { return false } @@ -46,11 +46,19 @@ public final class AccountManager: UnreadCountProvider { } public var sortedAccounts: [Account] { - return accountsSortedByName() + return sortByName(accounts) + } + + public var activeAccounts: [Account] { + return Array(accountsDictionary.values.filter { $0.isActive }) + } + + public var sortedActiveAccounts: [Account] { + return sortByName(activeAccounts) } public var refreshInProgress: Bool { - for account in accounts { + for account in activeAccounts { if account.refreshInProgress { return true } @@ -59,7 +67,7 @@ public final class AccountManager: UnreadCountProvider { } public var combinedRefreshProgress: CombinedRefreshProgress { - let downloadProgressArray = accounts.map { $0.refreshProgress } + let downloadProgressArray = activeAccounts.map { $0.refreshProgress } return CombinedRefreshProgress(downloadProgressArray: downloadProgressArray) } @@ -133,12 +141,12 @@ public final class AccountManager: UnreadCountProvider { public func refreshAll() { - accounts.forEach { $0.refreshAll() } + activeAccounts.forEach { $0.refreshAll() } } public func anyAccountHasAtLeastOneFeed() -> Bool { - for account in accounts { + for account in activeAccounts { if account.hasAtLeastOneFeed() { return true } @@ -149,7 +157,7 @@ public final class AccountManager: UnreadCountProvider { public func anyAccountHasFeedWithURL(_ urlString: String) -> Bool { - for account in accounts { + for account in activeAccounts { if let _ = account.existingFeed(withURL: urlString) { return true } @@ -159,7 +167,7 @@ public final class AccountManager: UnreadCountProvider { func updateUnreadCount() { - unreadCount = calculateUnreadCount(accounts) + unreadCount = calculateUnreadCount(activeAccounts) } // MARK: Notifications @@ -210,7 +218,7 @@ public final class AccountManager: UnreadCountProvider { } } - private func accountsSortedByName() -> [Account] { + private func sortByName(_ accounts: [Account]) -> [Account] { // LocalAccount is first. diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index b569cb758..41868c551 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -429,7 +429,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, @IBAction func debugDropConditionalGetInfo(_ sender: Any?) { #if DEBUG - AccountManager.shared.accounts.forEach{ $0.debugDropConditionalGetInfo() } + AccountManager.shared.activeAccounts.forEach{ $0.debugDropConditionalGetInfo() } #endif } diff --git a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift index 4086832ef..c4731fb3c 100644 --- a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift +++ b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift @@ -40,7 +40,7 @@ class AddFolderWindowController : NSWindowController { accountPopupButton.removeAllItems() let menu = NSMenu() - for oneAccount in AccountManager.shared.sortedAccounts { + for oneAccount in AccountManager.shared.sortedActiveAccounts { let oneMenuItem = NSMenuItem() oneMenuItem.title = oneAccount.nameForDisplay oneMenuItem.representedObject = oneAccount diff --git a/Mac/MainWindow/OPML/ExportOPMLWindowController.swift b/Mac/MainWindow/OPML/ExportOPMLWindowController.swift index fd6ba4650..86554200d 100644 --- a/Mac/MainWindow/OPML/ExportOPMLWindowController.swift +++ b/Mac/MainWindow/OPML/ExportOPMLWindowController.swift @@ -22,7 +22,7 @@ class ExportOPMLWindowController: NSWindowController { accountPopUpButton.removeAllItems() let menu = NSMenu() - for oneAccount in AccountManager.shared.sortedAccounts { + for oneAccount in AccountManager.shared.sortedActiveAccounts { let oneMenuItem = NSMenuItem() oneMenuItem.title = oneAccount.nameForDisplay oneMenuItem.representedObject = oneAccount diff --git a/Mac/MainWindow/OPML/ImportOPMLWindowController.swift b/Mac/MainWindow/OPML/ImportOPMLWindowController.swift index 355912c46..a587f3a9a 100644 --- a/Mac/MainWindow/OPML/ImportOPMLWindowController.swift +++ b/Mac/MainWindow/OPML/ImportOPMLWindowController.swift @@ -22,7 +22,7 @@ class ImportOPMLWindowController: NSWindowController { accountPopUpButton.removeAllItems() let menu = NSMenu() - for oneAccount in AccountManager.shared.sortedAccounts { + for oneAccount in AccountManager.shared.sortedActiveAccounts { let oneMenuItem = NSMenuItem() oneMenuItem.title = oneAccount.nameForDisplay oneMenuItem.representedObject = oneAccount diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index b1f64175e..559a9da11 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -54,6 +54,7 @@ protocol SidebarDelegate: class { NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChangeNotification(_:)), name: .AccountsDidChangeNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(accountStateDidChangeNotification(_:)), name: .AccountStateDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil) @@ -115,6 +116,10 @@ protocol SidebarDelegate: class { rebuildTreeAndRestoreSelection() } + @objc func accountStateDidChangeNotification(_ notification: Notification) { + rebuildTreeAndRestoreSelection() + } + @objc func batchUpdateDidPerform(_ notification: Notification) { rebuildTreeAndRestoreSelection() } diff --git a/Mac/Scriptability/NSApplication+Scriptability.swift b/Mac/Scriptability/NSApplication+Scriptability.swift index b94de03c9..c6d140688 100644 --- a/Mac/Scriptability/NSApplication+Scriptability.swift +++ b/Mac/Scriptability/NSApplication+Scriptability.swift @@ -56,13 +56,13 @@ extension NSApplication : ScriptingObjectContainer { @objc(accounts) func accounts() -> NSArray { - let accounts = AccountManager.shared.accounts + let accounts = AccountManager.shared.activeAccounts return accounts.map { ScriptableAccount($0) } as NSArray } @objc(valueInAccountsWithUniqueID:) func valueInAccounts(withUniqueID id:String) -> ScriptableAccount? { - let accounts = AccountManager.shared.accounts + let accounts = AccountManager.shared.activeAccounts guard let account = accounts.first(where:{$0.accountID == id}) else { return nil } return ScriptableAccount(account) } @@ -74,7 +74,7 @@ extension NSApplication : ScriptingObjectContainer { */ func allFeeds() -> [Feed] { - let accounts = AccountManager.shared.accounts + let accounts = AccountManager.shared.activeAccounts let emptyFeeds:[Feed] = [] return accounts.reduce(emptyFeeds) { (result, nthAccount) -> [Feed] in let accountFeeds = Array(nthAccount.topLevelFeeds) diff --git a/Shared/SmartFeeds/SearchFeedDelegate.swift b/Shared/SmartFeeds/SearchFeedDelegate.swift index 86d54c561..b68c8bf21 100644 --- a/Shared/SmartFeeds/SearchFeedDelegate.swift +++ b/Shared/SmartFeeds/SearchFeedDelegate.swift @@ -34,7 +34,7 @@ extension SearchFeedDelegate: ArticleFetcher { func fetchArticles() -> Set
{ var articles = Set
() - for account in AccountManager.shared.accounts { + for account in AccountManager.shared.activeAccounts { articles.formUnion(account.fetchArticlesMatching(searchString)) } return articles diff --git a/Shared/SmartFeeds/SmartFeed.swift b/Shared/SmartFeeds/SmartFeed.swift index 8c8cb8583..87ce35602 100644 --- a/Shared/SmartFeeds/SmartFeed.swift +++ b/Shared/SmartFeeds/SmartFeed.swift @@ -51,7 +51,7 @@ final class SmartFeed: PseudoFeed { } @objc func fetchUnreadCounts() { - AccountManager.shared.accounts.forEach { self.fetchUnreadCount(for: $0) } + AccountManager.shared.activeAccounts.forEach { self.fetchUnreadCount(for: $0) } } } @@ -80,7 +80,7 @@ private extension SmartFeed { } func updateUnreadCount() { - unreadCount = AccountManager.shared.accounts.reduce(0) { (result, account) -> Int in + unreadCount = AccountManager.shared.activeAccounts.reduce(0) { (result, account) -> Int in if let oneUnreadCount = unreadCounts[account] { return result + oneUnreadCount } diff --git a/Shared/SmartFeeds/StarredFeedDelegate.swift b/Shared/SmartFeeds/StarredFeedDelegate.swift index 81a93a92d..8f1553014 100644 --- a/Shared/SmartFeeds/StarredFeedDelegate.swift +++ b/Shared/SmartFeeds/StarredFeedDelegate.swift @@ -25,7 +25,7 @@ struct StarredFeedDelegate: SmartFeedDelegate { func fetchArticles() -> Set
{ var articles = Set
() - for account in AccountManager.shared.accounts { + for account in AccountManager.shared.activeAccounts { articles.formUnion(account.fetchStarredArticles()) } return articles diff --git a/Shared/SmartFeeds/TodayFeedDelegate.swift b/Shared/SmartFeeds/TodayFeedDelegate.swift index b23341b63..a06d7e623 100644 --- a/Shared/SmartFeeds/TodayFeedDelegate.swift +++ b/Shared/SmartFeeds/TodayFeedDelegate.swift @@ -24,7 +24,7 @@ struct TodayFeedDelegate: SmartFeedDelegate { func fetchArticles() -> Set
{ var articles = Set
() - for account in AccountManager.shared.accounts { + for account in AccountManager.shared.activeAccounts { articles.formUnion(account.fetchTodayArticles()) } return articles diff --git a/Shared/SmartFeeds/UnreadFeed.swift b/Shared/SmartFeeds/UnreadFeed.swift index cc04b0f6a..855311aa2 100644 --- a/Shared/SmartFeeds/UnreadFeed.swift +++ b/Shared/SmartFeeds/UnreadFeed.swift @@ -57,7 +57,7 @@ extension UnreadFeed: ArticleFetcher { func fetchUnreadArticles() -> Set
{ var articles = Set
() - for account in AccountManager.shared.accounts { + for account in AccountManager.shared.activeAccounts { articles.formUnion(account.fetchUnreadArticles()) } return articles diff --git a/Shared/Tree/FeedTreeControllerDelegate.swift b/Shared/Tree/FeedTreeControllerDelegate.swift index f674e125d..936efd4ea 100644 --- a/Shared/Tree/FeedTreeControllerDelegate.swift +++ b/Shared/Tree/FeedTreeControllerDelegate.swift @@ -113,7 +113,7 @@ private extension FeedTreeControllerDelegate { func sortedAccountNodes(_ parent: Node) -> [Node] { - let nodes = AccountManager.shared.sortedAccounts.map { (account) -> Node in + let nodes = AccountManager.shared.sortedActiveAccounts.map { (account) -> Node in let accountNode = parent.existingOrNewChildNode(with: account) accountNode.canHaveChildNodes = true accountNode.isGroupItem = true diff --git a/Shared/Tree/FolderTreeControllerDelegate.swift b/Shared/Tree/FolderTreeControllerDelegate.swift index 8bf769991..ca60e9e6d 100644 --- a/Shared/Tree/FolderTreeControllerDelegate.swift +++ b/Shared/Tree/FolderTreeControllerDelegate.swift @@ -24,7 +24,7 @@ private extension FolderTreeControllerDelegate { func childNodesForRootNode(_ node: Node) -> [Node]? { - let accountNodes: [Node] = AccountManager.shared.accounts.map { account in + let accountNodes: [Node] = AccountManager.shared.activeAccounts.map { account in let accountNode = Node(representedObject: account, parent: node) accountNode.canHaveChildNodes = true return accountNode diff --git a/iOS/Add/AddFolderViewController.swift b/iOS/Add/AddFolderViewController.swift index 1ad7be468..7bca799e3 100644 --- a/iOS/Add/AddFolderViewController.swift +++ b/iOS/Add/AddFolderViewController.swift @@ -24,7 +24,7 @@ class AddFolderViewController: UITableViewController, AddContainerViewController super.viewDidLoad() - accounts = AccountManager.shared.sortedAccounts + accounts = AccountManager.shared.sortedActiveAccounts accountLabel.text = (accounts[0] as DisplayNameProvider).nameForDisplay accountPickerView.dataSource = self diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 5a32a3969..61f7c9aed 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -398,7 +398,7 @@ class MasterFeedViewController: ProgressTableViewController, UndoableCommandRunn let markTitle = NSLocalizedString("Mark All Read", comment: "Mark All Read") let markAction = UIAlertAction(title: markTitle, style: .default) { [weak self] (action) in - let accounts = AccountManager.shared.accounts + let accounts = AccountManager.shared.activeAccounts var articles = Set
() accounts.forEach { account in articles.formUnion(account.fetchUnreadArticles())