Don't allow a feed to be in more than one folder for Reader API accounts

This commit is contained in:
Maurice Parker 2020-10-31 17:26:43 -05:00
parent 51d74eaf45
commit cbb481c3f7
3 changed files with 24 additions and 1 deletions

View File

@ -28,6 +28,11 @@ public enum AccountBehavior: Equatable {
*/
case disallowFeedInRootFolder
/**
Account doesn't support a feed being in more than one folder.
*/
case disallowFeedInMultipleFolders
/**
Account doesn't support folders
*/

View File

@ -29,7 +29,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "ReaderAPI")
var behaviors: AccountBehaviors {
var behaviors: AccountBehaviors = [.disallowOPMLImports]
var behaviors: AccountBehaviors = [.disallowOPMLImports, .disallowFeedInMultipleFolders]
if variant == .freshRSS {
behaviors.append(.disallowFeedInRootFolder)
}

View File

@ -644,6 +644,10 @@ private extension SidebarOutlineDataSource {
return true
}
if violatesDisallowFeedInMultipleFolders(parentNode, draggedFeeds) {
return true
}
return false
}
@ -677,6 +681,20 @@ private extension SidebarOutlineDataSource {
return false
}
func violatesDisallowFeedInMultipleFolders(_ parentNode: Node, _ draggedFeeds: Set<PasteboardWebFeed>) -> Bool {
guard let parentAccount = nodeAccount(parentNode), parentAccount.behaviors.contains(.disallowFeedInMultipleFolders) else {
return false
}
for draggedFeed in draggedFeeds {
if parentAccount.hasWebFeed(withURL: draggedFeed.url) {
return true
}
}
return false
}
func indexWhereDraggedFeedWouldAppear(_ parentNode: Node, _ draggedFeed: PasteboardWebFeed) -> Int {
let draggedFeedWrapper = PasteboardFeedObjectWrapper(pasteboardFeed: draggedFeed)
let draggedFeedNode = Node(representedObject: draggedFeedWrapper, parent: nil)