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:
parent
c07119feba
commit
ddccbdf610
|
@ -251,30 +251,13 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
return true // TODO
|
return true // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
public func addFeed(_ feed: Feed, to folder: Folder?) {
|
||||||
public func addFeed(_ feed: Feed, to folder: Folder?) -> Bool {
|
|
||||||
|
|
||||||
// Return false if it couldn’t be added.
|
|
||||||
// If it already existed in that folder, return true.
|
|
||||||
|
|
||||||
var didAddFeed = false
|
|
||||||
|
|
||||||
if let folder = folder {
|
if let folder = folder {
|
||||||
didAddFeed = folder.addFeed(feed)
|
folder.addFeed(feed)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if !topLevelFeeds.contains(feed) {
|
addFeed(feed)
|
||||||
topLevelFeeds.insert(feed)
|
|
||||||
postChildrenDidChangeNotification()
|
|
||||||
didAddFeed = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if didAddFeed {
|
|
||||||
structureDidChange()
|
|
||||||
}
|
|
||||||
|
|
||||||
return didAddFeed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func addFeeds(_ feeds: Set<Feed>, to folder: Folder?) {
|
public func addFeeds(_ feeds: Set<Feed>, to folder: Folder?) {
|
||||||
|
@ -282,9 +265,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
folder.addFeeds(feeds)
|
folder.addFeeds(feeds)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
topLevelFeeds.formUnion(feeds)
|
addFeeds(feeds)
|
||||||
}
|
}
|
||||||
structureDidChange()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func createFeed(with name: String?, editedName: String?, url: String) -> Feed? {
|
public func createFeed(with name: String?, editedName: String?, url: String) -> Feed? {
|
||||||
|
|
|
@ -29,7 +29,10 @@ public protocol Container: class {
|
||||||
|
|
||||||
func deleteFeed(_ feed: Feed)
|
func deleteFeed(_ feed: Feed)
|
||||||
func deleteFolder(_ folder: Folder)
|
func deleteFolder(_ folder: Folder)
|
||||||
|
|
||||||
|
func addFeed(_ feed: Feed)
|
||||||
|
func addFeeds(_ feeds: Set<Feed>)
|
||||||
|
|
||||||
//Recursive — checks subfolders
|
//Recursive — checks subfolders
|
||||||
func flattenedFeeds() -> Set<Feed>
|
func flattenedFeeds() -> Set<Feed>
|
||||||
func hasFeed(with feedID: String) -> Bool
|
func hasFeed(with feedID: String) -> Bool
|
||||||
|
@ -44,6 +47,18 @@ public protocol Container: class {
|
||||||
|
|
||||||
public extension Container {
|
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 {
|
func hasAtLeastOneFeed() -> Bool {
|
||||||
return topLevelFeeds.count > 0
|
return topLevelFeeds.count > 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// MARK: - Notifications
|
||||||
|
|
||||||
@objc func unreadCountDidChange(_ note: Notification) {
|
@objc func unreadCountDidChange(_ note: Notification) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ struct FeedsImporter {
|
||||||
let feedsToImport = feeds(with: feedDictionaries, account: account)
|
let feedsToImport = feeds(with: feedDictionaries, account: account)
|
||||||
|
|
||||||
BatchUpdate.shared.perform {
|
BatchUpdate.shared.perform {
|
||||||
feedsToImport.forEach{ account.addFeed($0, to: nil) }
|
feedsToImport.forEach{ account.addFeed($0) }
|
||||||
}
|
}
|
||||||
account.structureDidChange()
|
account.structureDidChange()
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,9 +181,8 @@ private extension AddFeedController {
|
||||||
account.update(feed, with: parsedFeed, {})
|
account.update(feed, with: parsedFeed, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
if account.addFeed(feed, to: userEnteredFolder) {
|
account.addFeed(feed, to: userEnteredFolder)
|
||||||
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
|
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Find Feeds
|
// MARK: Find Feeds
|
||||||
|
|
|
@ -230,8 +230,8 @@ private extension SidebarOutlineDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
BatchUpdate.shared.perform {
|
BatchUpdate.shared.perform {
|
||||||
account.addFeed(feed, to: destinationFolder)
|
|
||||||
sourceContainer?.deleteFeed(feed)
|
sourceContainer?.deleteFeed(feed)
|
||||||
|
account.addFeed(feed, to: destinationFolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -121,10 +121,9 @@ class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectContaine
|
||||||
account.update(feed, with:parsedFeed, {})
|
account.update(feed, with:parsedFeed, {})
|
||||||
|
|
||||||
// add the feed, putting it in a folder if needed
|
// add the feed, putting it in a folder if needed
|
||||||
if account.addFeed(feed, to:folder) {
|
account.addFeed(feed, to:folder)
|
||||||
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
|
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
|
||||||
}
|
|
||||||
|
|
||||||
let scriptableFeed = self.scriptableFeed(feed, account:account, folder:folder)
|
let scriptableFeed = self.scriptableFeed(feed, account:account, folder:folder)
|
||||||
command.resumeExecution(withResult:scriptableFeed.objectSpecifier)
|
command.resumeExecution(withResult:scriptableFeed.objectSpecifier)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue