From d1bc0c46cb669621960a44f6a1d12ca48bcdb2ba Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 24 Nov 2026 22:21:42 -0800 Subject: [PATCH] Put new Miniflux feed in category created in. Remove top level copies of feeds on refresh. --- .../Miniflux/MinifluxAccountDelegate.swift | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Modules/Account/Sources/Account/Miniflux/MinifluxAccountDelegate.swift b/Modules/Account/Sources/Account/Miniflux/MinifluxAccountDelegate.swift index 827be3d51..30e615785 100644 --- a/Modules/Account/Sources/Account/Miniflux/MinifluxAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Miniflux/MinifluxAccountDelegate.swift @@ -368,7 +368,7 @@ import Secrets refreshProgress.completeTask() uncompletedTasks -= 1 - return try await createFeed(account: account, feedID: feedID, name: name, container: container) + return try await createFeed(account: account, feedID: feedID, name: name, categoryID: categoryID) } } catch { throw AccountError.wrapped(error, account) @@ -686,9 +686,7 @@ private extension MinifluxAccountDelegate { let feedExternalIDs = Set(feeds.map { String($0.feedID) }) - // Remove any feeds that are no longer on the server. Miniflux guarantees every - // feed has a category, so feeds only ever live inside folders — never at the - // account top level. + // Remove any feeds that are no longer on the server. if let folders = account.folders { for folder in folders { for feed in folder.topLevelFeeds { @@ -704,6 +702,17 @@ private extension MinifluxAccountDelegate { } } + // Miniflux has no top level, so a top-level feed is either gone or belongs in its category’s folder. + let categorizedFeedExternalIDs = Set(feeds.filter { $0.category != nil }.map { String($0.feedID) }) + for feed in account.topLevelFeeds { + if !feedExternalIDs.contains(feed.feedID) { + account.clearFeedSettings(feed) + account.removeFeedFromTreeAtTopLevel(feed) + } else if categorizedFeedExternalIDs.contains(feed.feedID) { + account.removeFeedFromTreeAtTopLevel(feed) + } + } + // Add any feeds we don't have and update any we do. New feeds are added directly // to their folder in syncFeedFolderRelationship — Miniflux guarantees every feed // has exactly one category. @@ -1053,13 +1062,18 @@ private extension MinifluxAccountDelegate { } @discardableResult - func createFeed(account: Account, feedID: Int64, name: String?, container: Container) async throws -> Feed { + func createFeed(account: Account, feedID: Int64, name: String?, categoryID: Int64) async throws -> Feed { let minifluxFeed = try await caller.retrieveFeed(feedID: feedID) let feed = account.createFeed(with: minifluxFeed.title, url: minifluxFeed.feedURL, feedID: String(feedID), homePageURL: minifluxFeed.siteURL) feed.externalID = String(feedID) - try await account.addFeed(feed, container: container) + // The feed is already in this category on the server, so add it locally without another move. + if let folder = account.existingFolder(withExternalID: String(categoryID)) { + folder.addFeedToTreeAtTopLevel(feed) + } else { + account.addFeedToTreeAtTopLevel(feed) + } if let name { try await renameFeed(with: feed, to: name) }