From d70acc9b764a9aaefdb22fe9e26d30d65a4661ef Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 30 Sep 2026 20:34:33 -0700 Subject: [PATCH] Clean up on mark-all-read (and similar bulk commands). --- Shared/Commands/MarkStatusCommand.swift | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Shared/Commands/MarkStatusCommand.swift b/Shared/Commands/MarkStatusCommand.swift index e3d349a1f..5eb438519 100644 --- a/Shared/Commands/MarkStatusCommand.swift +++ b/Shared/Commands/MarkStatusCommand.swift @@ -21,10 +21,13 @@ import Articles let flag: Bool let statusKey: ArticleStatus.Key var completion: (() -> Void)? + // Called after every mark, with the flag that was applied, so undo and redo can update + // the UI in the right direction. Unlike completion, it’s not one-shot. + let didMark: ((Bool) -> Void)? - init?(initialArticles: [Article], statusKey: ArticleStatus.Key, flag: Bool, undoManager: UndoManager, completion: (() -> Void)? = nil) { + init?(initialArticles: [Article], statusKey: ArticleStatus.Key, flag: Bool, undoManager: UndoManager, completion: (() -> Void)? = nil, didMark: ((Bool) -> Void)? = nil) { - // Filter out articles that already have the desired status or can't be marked. + // Filter out articles that already have the desired status or can’t be marked. let articlesToMark = MarkStatusCommand.filteredArticles(initialArticles, statusKey, flag) if articlesToMark.isEmpty { completion?() @@ -36,6 +39,7 @@ import Articles self.statusKey = statusKey self.undoManager = undoManager self.completion = completion + self.didMark = didMark let actionName = MarkStatusCommand.actionName(statusKey, flag) self.undoActionName = actionName @@ -64,8 +68,14 @@ import Articles @MainActor private extension MarkStatusCommand { func mark(_ statusKey: ArticleStatus.Key, _ flag: Bool) { - markArticleIDs(articleIDsByAccountID, statusKey: statusKey, flag: flag, completion: completion) - completion = nil + let completion = self.completion + let didMark = self.didMark + self.completion = nil + + markArticleIDs(articleIDsByAccountID, statusKey: statusKey, flag: flag) { + completion?() + didMark?(flag) + } } static private let markReadActionName = NSLocalizedString("Mark Read", comment: "command")