Prevent dragging between accounts.

This commit is contained in:
Maurice Parker 2019-05-01 17:49:25 -05:00
parent 78e98e4c03
commit 133398c240

View File

@ -173,6 +173,9 @@ private extension SidebarOutlineDataSource {
guard let dropTargetNode = ancestorThatCanAcceptLocalFeed(parentNode) else {
return SidebarOutlineDataSource.dragOperationNone
}
if nodeAndDraggedFeedsDoNotShareAccount(dropTargetNode, Set([draggedFeed])) {
return SidebarOutlineDataSource.dragOperationNone
}
if nodeHasChildRepresentingDraggedFeed(dropTargetNode, draggedFeed) {
return SidebarOutlineDataSource.dragOperationNone
}
@ -191,6 +194,9 @@ private extension SidebarOutlineDataSource {
guard let dropTargetNode = ancestorThatCanAcceptLocalFeed(parentNode) else {
return SidebarOutlineDataSource.dragOperationNone
}
if nodeAndDraggedFeedsDoNotShareAccount(dropTargetNode, draggedFeeds) {
return SidebarOutlineDataSource.dragOperationNone
}
if nodeHasChildRepresentingAnyDraggedFeed(dropTargetNode, draggedFeeds) {
return SidebarOutlineDataSource.dragOperationNone
}
@ -321,6 +327,27 @@ private extension SidebarOutlineDataSource {
}
return false
}
func nodeAndDraggedFeedsDoNotShareAccount(_ parentNode: Node, _ draggedFeeds: Set<PasteboardFeed>) -> Bool {
let parentAccountId: String?
if let account = parentNode.representedObject as? Account {
parentAccountId = account.accountID
} else if let folder = parentNode.representedObject as? Folder {
parentAccountId = folder.account?.accountID
} else {
return true
}
for draggedFeed in draggedFeeds {
if draggedFeed.accountID != parentAccountId {
return true
}
}
return false
}
func nodeHasChildRepresentingAnyDraggedFeed(_ parentNode: Node, _ draggedFeeds: Set<PasteboardFeed>) -> Bool {
for node in parentNode.childNodes {