mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-02 12:06:58 +01:00
Refactor addFeed and removeFeed usages to be more consistent
This commit is contained in:
parent
5e3fcfd955
commit
f4bc17c8f1
@ -61,6 +61,9 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
return defaultName
|
||||
}()
|
||||
|
||||
public var account: Account? {
|
||||
return self
|
||||
}
|
||||
public let accountID: String
|
||||
public let type: AccountType
|
||||
public var nameForDisplay: String {
|
||||
@ -373,11 +376,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
return feed
|
||||
}
|
||||
|
||||
func addFeed(container: Container, feed: Feed, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
public func addFeed(_ feed: Feed, to container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.addFeed(for: self, to: container, with: feed, completion: completion)
|
||||
}
|
||||
|
||||
func removeFeed(_ feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
public func removeFeed(_ feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.removeFeed(for: self, from: container, with: feed, completion: completion)
|
||||
}
|
||||
|
||||
@ -659,21 +662,13 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
return _flattenedFeeds
|
||||
}
|
||||
|
||||
public func removeFeed(_ feed: Feed, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.removeFeed(for: self, from: self, with: feed, completion: completion)
|
||||
}
|
||||
|
||||
public func addFeed(_ feed: Feed, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.addFeed(for: self, to: self, with: feed, completion: completion)
|
||||
}
|
||||
|
||||
func removeFeed(_ feed: Feed) {
|
||||
public func removeFeed(_ feed: Feed) {
|
||||
topLevelFeeds.remove(feed)
|
||||
structureDidChange()
|
||||
postChildrenDidChangeNotification()
|
||||
}
|
||||
|
||||
func addFeed(_ feed: Feed) {
|
||||
public func addFeed(_ feed: Feed) {
|
||||
topLevelFeeds.insert(feed)
|
||||
structureDidChange()
|
||||
postChildrenDidChangeNotification()
|
||||
|
@ -18,6 +18,7 @@ extension Notification.Name {
|
||||
|
||||
public protocol Container: class {
|
||||
|
||||
var account: Account? { get }
|
||||
var topLevelFeeds: Set<Feed> { get set }
|
||||
var folders: Set<Folder>? { get set }
|
||||
|
||||
@ -27,8 +28,8 @@ public protocol Container: class {
|
||||
func hasChildFolder(with: String) -> Bool
|
||||
func childFolder(with: String) -> Folder?
|
||||
|
||||
func removeFeed(_ feed: Feed, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func addFeed(_ feed: Feed, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func removeFeed(_ feed: Feed)
|
||||
func addFeed(_ feed: Feed)
|
||||
|
||||
//Recursive — checks subfolders
|
||||
func flattenedFeeds() -> Set<Feed>
|
||||
|
@ -870,7 +870,7 @@ private extension FeedbinAccountDelegate {
|
||||
let feed = account.createFeed(with: sub.name, url: sub.url, feedID: String(sub.feedID), homePageURL: sub.homePageURL)
|
||||
feed.subscriptionID = String(sub.subscriptionID)
|
||||
|
||||
container.addFeed(feed) { result in
|
||||
account.addFeed(feed, to: container) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
if let name = name {
|
||||
|
@ -95,20 +95,12 @@ public final class Folder: DisplayNameProvider, Renamable, Container, UnreadCoun
|
||||
return topLevelFeeds.contains(feed)
|
||||
}
|
||||
|
||||
public func addFeed(_ feed: Feed, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
account?.addFeed(container: self, feed: feed, completion: completion)
|
||||
}
|
||||
|
||||
public func removeFeed(_ feed: Feed, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
account?.removeFeed(feed, from: self, completion: completion)
|
||||
}
|
||||
|
||||
func addFeed(_ feed: Feed) {
|
||||
public func addFeed(_ feed: Feed) {
|
||||
topLevelFeeds.insert(feed)
|
||||
postChildrenDidChangeNotification()
|
||||
}
|
||||
|
||||
func removeFeed(_ feed: Feed) {
|
||||
public func removeFeed(_ feed: Feed) {
|
||||
topLevelFeeds.remove(feed)
|
||||
postChildrenDidChangeNotification()
|
||||
}
|
||||
|
@ -123,36 +123,26 @@ final class LocalAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
func deleteFeed(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
if let account = container as? Account {
|
||||
account.removeFeed(feed)
|
||||
}
|
||||
if let folder = container as? Folder {
|
||||
folder.removeFeed(feed)
|
||||
}
|
||||
container?.removeFeed(feed)
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
func addFeed(for account: Account, to container: Container, with feed: Feed, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
container.addFeed(feed)
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
func removeFeed(for account: Account, from container: Container, with feed: Feed, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
container.removeFeed(feed)
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
if let folder = container as? Folder {
|
||||
folder.addFeed(feed)
|
||||
} else if let account = container as? Account {
|
||||
account.addFeed(feed)
|
||||
}
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
func removeFeed(for account: Account, from container: Container, with feed: Feed, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
if let account = container as? Account {
|
||||
account.removeFeed(feed)
|
||||
}
|
||||
if let folder = container as? Folder {
|
||||
folder.removeFeed(feed)
|
||||
}
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
container.addFeed(feed, completion: completion)
|
||||
}
|
||||
|
||||
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
@ -210,14 +200,8 @@ extension LocalAccountDelegate: FeedFinderDelegate {
|
||||
|
||||
feed.editedName = self.createFeedName
|
||||
|
||||
self.createFeedContainer?.addFeed(feed) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.createFeedCompletion?(.success(feed))
|
||||
case .failure(let error):
|
||||
self.createFeedCompletion?(.failure(error))
|
||||
}
|
||||
}
|
||||
self.createFeedContainer?.addFeed(feed)
|
||||
self.createFeedCompletion?(.success(feed))
|
||||
|
||||
}
|
||||
|
||||
|
@ -285,13 +285,11 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
|
||||
func copyInAccount(node: Node, to parentNode: Node) {
|
||||
guard let feed = node.representedObject as? Feed else {
|
||||
guard let feed = node.representedObject as? Feed, let destination = parentNode.representedObject as? Container else {
|
||||
return
|
||||
}
|
||||
|
||||
let destination = parentNode.representedObject as? Container
|
||||
|
||||
destination?.addFeed(feed) { result in
|
||||
destination.account?.addFeed(feed, to: destination) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
@ -302,18 +300,17 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
|
||||
func moveInAccount(node: Node, to parentNode: Node) {
|
||||
guard let feed = node.representedObject as? Feed else {
|
||||
guard let feed = node.representedObject as? Feed,
|
||||
let source = node.parent?.representedObject as? Container,
|
||||
let destination = parentNode.representedObject as? Container else {
|
||||
return
|
||||
}
|
||||
|
||||
let source = node.parent?.representedObject as? Container
|
||||
let destination = parentNode.representedObject as? Container
|
||||
|
||||
BatchUpdate.shared.start()
|
||||
source?.removeFeed(feed) { result in
|
||||
source.account?.removeFeed(feed, from: source) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
destination?.addFeed(feed) { result in
|
||||
destination.account?.addFeed(feed, to: destination) { result in
|
||||
BatchUpdate.shared.end()
|
||||
switch result {
|
||||
case .success:
|
||||
@ -336,7 +333,7 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
|
||||
if let existingFeed = destinationAccount.existingFeed(withURL: feed.url) {
|
||||
destinationContainer.addFeed(existingFeed) { result in
|
||||
destinationAccount.addFeed(existingFeed, to: destinationContainer) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
@ -368,7 +365,7 @@ private extension SidebarOutlineDataSource {
|
||||
if let existingFeed = destinationAccount.existingFeed(withURL: feed.url) {
|
||||
|
||||
BatchUpdate.shared.start()
|
||||
destinationContainer.addFeed(existingFeed) { result in
|
||||
destinationAccount.addFeed(existingFeed, to: destinationContainer) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
sourceAccount.deleteFeed(feed, from: sourceContainer) { result in
|
||||
|
Loading…
x
Reference in New Issue
Block a user