Make hasAtLeastOneFeed() a Container protocol function with a default implementation. Scrap Account’s feedIDDictionary, since it’s not needed. (Well, profiling may tell us later to bring it back.)

This commit is contained in:
Brent Simmons 2017-10-18 18:45:09 -07:00
parent fe29ccd2ed
commit 39599a43f3
3 changed files with 19 additions and 20 deletions

View File

@ -53,7 +53,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
let dataFolder: String
let database: Database
let delegate: AccountDelegate
var feedIDDictionary = [String: Feed]()
var username: String?
var saveTimer: Timer?
@ -106,12 +105,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
}
var hasAtLeastOneFeed: Bool {
get {
return !feedIDDictionary.isEmpty
}
}
var supportsSubFolders: Bool {
get {
return delegate.supportsSubFolders
@ -215,7 +208,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
didAddFeed = true
}
updateFeedIDDictionary()
return didAddFeed // TODO
}
@ -346,7 +338,6 @@ private extension Account {
return
}
children = objects(with: childrenArray)
updateFeedIDDictionary()
}
func diskDictionary() -> NSDictionary {
@ -413,15 +404,6 @@ private extension Account {
private extension Account {
func updateFeedIDDictionary() {
var d = [String: Feed]()
for feed in flattenedFeeds() {
d[feed.feedID] = feed
}
feedIDDictionary = d
}
func topLevelObjectsContainsFeed(_ feed: Feed) -> Bool {
return children.contains(where: { (object) -> Bool in

View File

@ -101,7 +101,7 @@ public final class AccountManager: UnreadCountProvider {
public func anyAccountHasAtLeastOneFeed() -> Bool {
for account in accounts {
if account.hasAtLeastOneFeed {
if account.hasAtLeastOneFeed() {
return true
}
}

View File

@ -19,7 +19,8 @@ extension NSNotification.Name {
public protocol Container {
var children: [AnyObject] { get }
func hasAtLeastOneFeed() -> Bool
func objectIsChild(_ object: AnyObject) -> Bool
//Recursive
@ -35,6 +36,22 @@ public protocol Container {
public extension Container {
func hasAtLeastOneFeed() -> Bool {
for child in children {
if let feed = child as? Feed {
return true
}
if let folder = child as? Folder {
if folder.hasAtLeastOneFeed() {
return true
}
}
}
return false
}
func objectIsChild(_ object: AnyObject) -> Bool {
for child in children {