Implement active account processing functionality

This commit is contained in:
Maurice Parker 2019-05-02 06:01:30 -05:00
parent 747079157b
commit 636468bbf0
16 changed files with 39 additions and 26 deletions

View File

@ -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.

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()
}

View File

@ -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)

View File

@ -34,7 +34,7 @@ extension SearchFeedDelegate: ArticleFetcher {
func fetchArticles() -> Set<Article> {
var articles = Set<Article>()
for account in AccountManager.shared.accounts {
for account in AccountManager.shared.activeAccounts {
articles.formUnion(account.fetchArticlesMatching(searchString))
}
return articles

View File

@ -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
}

View File

@ -25,7 +25,7 @@ struct StarredFeedDelegate: SmartFeedDelegate {
func fetchArticles() -> Set<Article> {
var articles = Set<Article>()
for account in AccountManager.shared.accounts {
for account in AccountManager.shared.activeAccounts {
articles.formUnion(account.fetchStarredArticles())
}
return articles

View File

@ -24,7 +24,7 @@ struct TodayFeedDelegate: SmartFeedDelegate {
func fetchArticles() -> Set<Article> {
var articles = Set<Article>()
for account in AccountManager.shared.accounts {
for account in AccountManager.shared.activeAccounts {
articles.formUnion(account.fetchTodayArticles())
}
return articles

View File

@ -57,7 +57,7 @@ extension UnreadFeed: ArticleFetcher {
func fetchUnreadArticles() -> Set<Article> {
var articles = Set<Article>()
for account in AccountManager.shared.accounts {
for account in AccountManager.shared.activeAccounts {
articles.formUnion(account.fetchUnreadArticles())
}
return articles

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<Article>()
accounts.forEach { account in
articles.formUnion(account.fetchUnreadArticles())