From c4f7090b9c7cbcd6154d70100db8854305d69f71 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 8 Sep 2019 09:58:27 -0500 Subject: [PATCH] Automatically expand any activated accounts and clean up the expandedNodes table for inactivated accounts --- Frameworks/Account/Account.swift | 4 +++- iOS/SceneCoordinator.swift | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index a39389716..733c3cd03 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -118,7 +118,9 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, set { if newValue != metadata.isActive { metadata.isActive = newValue - NotificationCenter.default.post(name: .AccountStateDidChange, object: self, userInfo: nil) + var userInfo = [AnyHashable: Any]() + userInfo[UserInfoKey.account] = self + NotificationCenter.default.post(name: .AccountStateDidChange, object: self, userInfo: userInfo) } } } diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index b6260a7c4..8db81d157 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -360,7 +360,25 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { if timelineFetcherContainsAnyPseudoFeed() { fetchAndReplaceArticlesSync() } - rebuildBackingStores() + + guard let account = note.userInfo?[Account.UserInfoKey.account] as? Account else { + assertionFailure() + return + } + + // If we are deactivating an account, clean up the expandedNodes table + if !account.isActive, let node = self.treeController.rootNode.childNodeRepresentingObject(account) { + if let nodeIndex = self.expandedNodes.firstIndex(of: node) { + self.expandedNodes.remove(at: nodeIndex) + } + } + + rebuildBackingStores() { + // If we are activating an account, then automatically expand it + if account.isActive, let node = self.treeController.rootNode.childNodeRepresentingObject(account) { + self.expandedNodes.append(node) + } + } } @objc func userDidAddAccount(_ note: Notification) { @@ -369,6 +387,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } rebuildBackingStores() { + // Automatically expand any new accounts if let account = note.userInfo?[Account.UserInfoKey.account] as? Account, let node = self.treeController.rootNode.childNodeRepresentingObject(account) { self.expandedNodes.append(node) @@ -382,6 +401,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } rebuildBackingStores() { + // Clean up the expandedNodes table for any deleted accounts if let account = note.userInfo?[Account.UserInfoKey.account] as? Account, let node = self.treeController.rootNode.childNodeRepresentingObject(account), let nodeIndex = self.expandedNodes.firstIndex(of: node) {