Fix duplicate folder relationships caused by OPMLNormalizer

This commit is contained in:
Maurice Parker 2020-04-12 18:29:34 -05:00
parent b38f720a62
commit 6bd2c0dc06
2 changed files with 6 additions and 23 deletions

View File

@ -202,22 +202,7 @@ final class CloudKitAccountDelegate: AccountDelegate {
let normalizedItems = OPMLNormalizer.normalize(opmlItems)
// Combine all existing web feed URLs with all the new ones
var webFeedURLs = account.flattenedWebFeedURLs
for opmlItem in normalizedItems {
if let webFeedURL = opmlItem.feedSpecifier?.feedURL {
webFeedURLs.insert(webFeedURL)
} else {
if let childItems = opmlItem.children {
for childItem in childItems {
if let webFeedURL = childItem.feedSpecifier?.feedURL {
webFeedURLs.insert(webFeedURL)
}
}
}
}
}
// TODO: remove duplicates created by import
self.accountZone.importOPML(rootExternalID: rootExternalID, items: normalizedItems) { _ in
self.refreshAll(for: account, downloadFeeds: false, completion: completion)

View File

@ -23,9 +23,8 @@ final class OPMLNormalizer {
var feedsToAdd = [RSOPMLItem]()
items.forEach { (item) in
if let _ = item.feedSpecifier {
if !feedsToAdd.contains(where: { $0.feedSpecifier?.feedURL == item.feedSpecifier?.feedURL } ) {
if !feedsToAdd.contains(where: { $0.feedSpecifier?.feedURL == item.feedSpecifier?.feedURL }) {
feedsToAdd.append(item)
}
return
@ -39,15 +38,14 @@ final class OPMLNormalizer {
return
}
normalizedOPMLItems.append(item)
if let itemChildren = item.children {
normalize(itemChildren, parentFolder: item)
}
feedsToAdd.append(item)
}
if let parentFolder = parentFolder {
for feed in feedsToAdd {
parentFolder.addChild(feed)
if !(parentFolder.children?.contains(where: { $0.feedSpecifier?.feedURL == feed.feedSpecifier?.feedURL}) ?? false) {
parentFolder.addChild(feed)
}
}
} else {
for feed in feedsToAdd {