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:
parent
fe29ccd2ed
commit
39599a43f3
|
@ -53,7 +53,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
let dataFolder: String
|
let dataFolder: String
|
||||||
let database: Database
|
let database: Database
|
||||||
let delegate: AccountDelegate
|
let delegate: AccountDelegate
|
||||||
var feedIDDictionary = [String: Feed]()
|
|
||||||
var username: String?
|
var username: String?
|
||||||
var saveTimer: Timer?
|
var saveTimer: Timer?
|
||||||
|
|
||||||
|
@ -106,12 +105,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasAtLeastOneFeed: Bool {
|
|
||||||
get {
|
|
||||||
return !feedIDDictionary.isEmpty
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var supportsSubFolders: Bool {
|
var supportsSubFolders: Bool {
|
||||||
get {
|
get {
|
||||||
return delegate.supportsSubFolders
|
return delegate.supportsSubFolders
|
||||||
|
@ -215,7 +208,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
didAddFeed = true
|
didAddFeed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFeedIDDictionary()
|
|
||||||
return didAddFeed // TODO
|
return didAddFeed // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +338,6 @@ private extension Account {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
children = objects(with: childrenArray)
|
children = objects(with: childrenArray)
|
||||||
updateFeedIDDictionary()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func diskDictionary() -> NSDictionary {
|
func diskDictionary() -> NSDictionary {
|
||||||
|
@ -413,15 +404,6 @@ private extension Account {
|
||||||
|
|
||||||
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 {
|
func topLevelObjectsContainsFeed(_ feed: Feed) -> Bool {
|
||||||
|
|
||||||
return children.contains(where: { (object) -> Bool in
|
return children.contains(where: { (object) -> Bool in
|
||||||
|
|
|
@ -101,7 +101,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||||
public func anyAccountHasAtLeastOneFeed() -> Bool {
|
public func anyAccountHasAtLeastOneFeed() -> Bool {
|
||||||
|
|
||||||
for account in accounts {
|
for account in accounts {
|
||||||
if account.hasAtLeastOneFeed {
|
if account.hasAtLeastOneFeed() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ public protocol Container {
|
||||||
|
|
||||||
var children: [AnyObject] { get }
|
var children: [AnyObject] { get }
|
||||||
|
|
||||||
|
func hasAtLeastOneFeed() -> Bool
|
||||||
func objectIsChild(_ object: AnyObject) -> Bool
|
func objectIsChild(_ object: AnyObject) -> Bool
|
||||||
|
|
||||||
//Recursive
|
//Recursive
|
||||||
|
@ -35,6 +36,22 @@ public protocol Container {
|
||||||
|
|
||||||
public extension 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 {
|
func objectIsChild(_ object: AnyObject) -> Bool {
|
||||||
|
|
||||||
for child in children {
|
for child in children {
|
||||||
|
|
Loading…
Reference in New Issue