Fix feed not showing up at account-level if it's also in another folder

This commit is contained in:
Anh Do 2020-03-21 20:54:16 -04:00
parent 51a4a2b3c8
commit a9615560ae
No known key found for this signature in database
GPG Key ID: 451E3092F917B62D
2 changed files with 8 additions and 18 deletions

View File

@ -66,8 +66,9 @@ extension NewsBlurAccountDelegate {
}()
// Make any folders NewsBlur has, but we don't
// Ignore account-level folder
folderNames.forEach { folderName in
if !accountFolderNames.contains(folderName) {
if !accountFolderNames.contains(folderName) && folderName != " " {
_ = account.ensureFolder(with: folderName)
}
}
@ -133,7 +134,7 @@ extension NewsBlurAccountDelegate {
// Set up some structures to make syncing easier
let relationships = folders.map({ $0.asRelationships }).flatMap { $0 }
let folderDict = nameToFolderDictionary(with: account.folders)
let foldersDict = relationships.reduce([String: [NewsBlurFolderRelationship]]()) { (dict, relationship) in
let newsBlurFolderDict = relationships.reduce([String: [NewsBlurFolderRelationship]]()) { (dict, relationship) in
var feedInFolders = dict
if var feedInFolder = feedInFolders[relationship.folderName] {
feedInFolder.append(relationship)
@ -145,14 +146,14 @@ extension NewsBlurAccountDelegate {
}
// Sync the folders
for (folderName, folderRelationships) in foldersDict {
for (folderName, folderRelationships) in newsBlurFolderDict {
guard let folder = folderDict[folderName] else { return }
let folderFeedIDs = folderRelationships.map { String($0.feedID) }
let newsBlurFolderFeedIDs = folderRelationships.map { String($0.feedID) }
// Move any feeds not in the folder to the account
for feed in folder.topLevelWebFeeds {
if !folderFeedIDs.contains(feed.webFeedID) {
if !newsBlurFolderFeedIDs.contains(feed.webFeedID) {
folder.removeWebFeed(feed)
clearFolderRelationship(for: feed, withFolderName: folder.name ?? "")
account.addWebFeed(feed)
@ -172,16 +173,6 @@ extension NewsBlurAccountDelegate {
folder.addWebFeed(feed)
}
}
}
let folderFeedIDs = Set(relationships.map { String($0.feedID) })
// Remove all feeds from the account container that have a tag
for feed in account.topLevelWebFeeds {
if folderFeedIDs.contains(feed.webFeedID) {
account.removeWebFeed(feed)
}
}
}

View File

@ -34,7 +34,7 @@ struct NewsBlurAddURLResponse: Decodable {
let feed: NewsBlurFeed?
}
struct NewsBlurFolderRelationship: Codable {
struct NewsBlurFolderRelationship {
let folderName: String
let feedID: Int
}
@ -71,8 +71,7 @@ extension NewsBlurFeedsResponse {
var folders: [Folder] = []
let folderContainer = try container.nestedContainer(keyedBy: NewsBlurGenericCodingKeys.self, forKey: .folders)
// Skip "everything" folder
for key in folderContainer.allKeys where key.stringValue != " " {
for key in folderContainer.allKeys {
let subscriptionIds = try folderContainer.decode([Int].self, forKey: key)
let folder = Folder(name: key.stringValue, feedIDs: subscriptionIds)