From cbb481c3f7f8cc753ce65c7ddaf22c71a044c9e4 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 31 Oct 2020 17:26:43 -0500 Subject: [PATCH] Don't allow a feed to be in more than one folder for Reader API accounts --- Account/Sources/Account/AccountBehaviors.swift | 5 +++++ .../ReaderAPI/ReaderAPIAccountDelegate.swift | 2 +- .../Sidebar/SidebarOutlineDataSource.swift | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Account/Sources/Account/AccountBehaviors.swift b/Account/Sources/Account/AccountBehaviors.swift index 90776cdd3..fed082b4c 100644 --- a/Account/Sources/Account/AccountBehaviors.swift +++ b/Account/Sources/Account/AccountBehaviors.swift @@ -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 */ diff --git a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 60eeecd14..8d9310cc8 100644 --- a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -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) } diff --git a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift index ec919b073..df593b664 100644 --- a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift +++ b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift @@ -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) -> 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)