From f4e0cfaf2bac05cb545350f3228afe278ce12d7a Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 7 Jun 2019 05:03:54 -0500 Subject: [PATCH] Fix folder renaming issue that occurs for Feedbin when the tag doesn't exist at Feedbin. Issue #724 --- .../Feedbin/FeedbinAccountDelegate.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index a6b0ba756..f6711fc8a 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -243,10 +243,16 @@ final class FeedbinAccountDelegate: AccountDelegate { func renameFolder(for account: Account, with folder: Folder, to name: String, completion: @escaping (Result) -> Void) { + guard folder.hasAtLeastOneFeed() else { + folder.name = name + return + } + caller.renameTag(oldName: folder.name ?? "", newName: name) { result in switch result { case .success: DispatchQueue.main.async { + self.renameFolderRelationship(for: account, fromName: folder.name ?? "", toName: name) folder.name = name completion(.success(())) } @@ -840,6 +846,17 @@ private extension FeedbinAccountDelegate { } + func renameFolderRelationship(for account: Account, fromName: String, toName: String) { + for feed in account.flattenedFeeds() { + if var folderRelationship = feed.folderRelationship { + let relationship = folderRelationship[fromName] + folderRelationship[fromName] = nil + folderRelationship[toName] = relationship + feed.folderRelationship = folderRelationship + } + } + } + func clearFolderRelationship(for feed: Feed, withFolderName folderName: String) { if var folderRelationship = feed.folderRelationship { folderRelationship[folderName] = nil