From 6bd2c0dc0675f7974b0f84e2448d5e0a6a16d69c Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 12 Apr 2020 18:29:34 -0500 Subject: [PATCH] Fix duplicate folder relationships caused by OPMLNormalizer --- .../CloudKit/CloudKitAccountDelegate.swift | 17 +---------------- Frameworks/Account/OPMLNormalizer.swift | 12 +++++------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift b/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift index 1d60510d3..63572332e 100644 --- a/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift @@ -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) diff --git a/Frameworks/Account/OPMLNormalizer.swift b/Frameworks/Account/OPMLNormalizer.swift index dee350ee3..76dc084c3 100644 --- a/Frameworks/Account/OPMLNormalizer.swift +++ b/Frameworks/Account/OPMLNormalizer.swift @@ -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 {