Add addFeed and addFeeds to the Container protocol. This was confusing before. Now you can add directly to a Folder or Account.

This commit is contained in:
Brent Simmons 2019-02-05 21:48:32 -08:00
parent c07119feba
commit ddccbdf610
7 changed files with 27 additions and 52 deletions

View File

@ -251,30 +251,13 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
return true // TODO
}
@discardableResult
public func addFeed(_ feed: Feed, to folder: Folder?) -> Bool {
// Return false if it couldnt be added.
// If it already existed in that folder, return true.
var didAddFeed = false
public func addFeed(_ feed: Feed, to folder: Folder?) {
if let folder = folder {
didAddFeed = folder.addFeed(feed)
folder.addFeed(feed)
}
else {
if !topLevelFeeds.contains(feed) {
topLevelFeeds.insert(feed)
postChildrenDidChangeNotification()
didAddFeed = true
}
addFeed(feed)
}
if didAddFeed {
structureDidChange()
}
return didAddFeed
}
public func addFeeds(_ feeds: Set<Feed>, to folder: Folder?) {
@ -282,9 +265,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
folder.addFeeds(feeds)
}
else {
topLevelFeeds.formUnion(feeds)
addFeeds(feeds)
}
structureDidChange()
}
public func createFeed(with name: String?, editedName: String?, url: String) -> Feed? {

View File

@ -29,7 +29,10 @@ public protocol Container: class {
func deleteFeed(_ feed: Feed)
func deleteFolder(_ folder: Folder)
func addFeed(_ feed: Feed)
func addFeeds(_ feeds: Set<Feed>)
//Recursive  checks subfolders
func flattenedFeeds() -> Set<Feed>
func hasFeed(with feedID: String) -> Bool
@ -44,6 +47,18 @@ public protocol Container: class {
public extension Container {
func addFeed(_ feed: Feed) {
addFeeds(Set([feed]))
}
func addFeeds(_ feeds: Set<Feed>) {
let feedCount = topLevelFeeds.count
topLevelFeeds.formUnion(feeds)
if feedCount != topLevelFeeds.count {
postChildrenDidChangeNotification()
}
}
func hasAtLeastOneFeed() -> Bool {
return topLevelFeeds.count > 0
}

View File

@ -81,26 +81,6 @@ public final class Folder: DisplayNameProvider, Renamable, Container, UnreadCoun
}
}
// MARK: Feeds
/// Add a single feed. Return true if number of feeds in folder changes.
func addFeed(_ feed: Feed) -> Bool {
return addFeeds(Set([feed]))
}
/// Add one or more feeds. Return true if number of feeds in folder changes.
@discardableResult
func addFeeds(_ feedsToAdd: Set<Feed>) -> Bool {
let feedCount = topLevelFeeds.count
topLevelFeeds.formUnion(feedsToAdd)
if feedCount != topLevelFeeds.count {
postChildrenDidChangeNotification()
return true
}
return false
}
// MARK: - Notifications
@objc func unreadCountDidChange(_ note: Notification) {

View File

@ -45,7 +45,7 @@ struct FeedsImporter {
let feedsToImport = feeds(with: feedDictionaries, account: account)
BatchUpdate.shared.perform {
feedsToImport.forEach{ account.addFeed($0, to: nil) }
feedsToImport.forEach{ account.addFeed($0) }
}
account.structureDidChange()
}

View File

@ -181,9 +181,8 @@ private extension AddFeedController {
account.update(feed, with: parsedFeed, {})
}
if account.addFeed(feed, to: userEnteredFolder) {
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
}
account.addFeed(feed, to: userEnteredFolder)
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
}
// MARK: Find Feeds

View File

@ -230,8 +230,8 @@ private extension SidebarOutlineDataSource {
}
BatchUpdate.shared.perform {
account.addFeed(feed, to: destinationFolder)
sourceContainer?.deleteFeed(feed)
account.addFeed(feed, to: destinationFolder)
}
return true

View File

@ -121,10 +121,9 @@ class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectContaine
account.update(feed, with:parsedFeed, {})
// add the feed, putting it in a folder if needed
if account.addFeed(feed, to:folder) {
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
}
account.addFeed(feed, to:folder)
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
let scriptableFeed = self.scriptableFeed(feed, account:account, folder:folder)
command.resumeExecution(withResult:scriptableFeed.objectSpecifier)
} else {