diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 61b76c648..c2e1aae87 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -134,6 +134,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } // MARK: - API + + func manualRefresh(errorHandler: @escaping (Error) -> ()) { + UIApplication.shared.connectedScenes.compactMap( { $0.delegate as? SceneDelegate } ).forEach { + $0.refreshInterface() + } + AccountManager.shared.refreshAll(errorHandler: errorHandler) + } + func resumeDatabaseProcessingIfNecessary() { if AccountManager.shared.isSuspended { AccountManager.shared.resumeAll() diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 86382a44f..9b0e2fdfa 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -426,11 +426,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { // This is a hack to make sure that an error dialog doesn't interfere with dismissing the refreshControl. // If the error dialog appears too closely to the call to endRefreshing, then the refreshControl never disappears. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - AccountManager.shared.refreshAll(errorHandler: ErrorHandler.present(self)) { - if AppDefaults.refreshClearsReadArticles { - self.coordinator.refreshTimeline(resetScroll: false) - } - } + appDelegate.manualRefresh(errorHandler: ErrorHandler.present(self)) } } diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index 85417b3ab..52ee82cee 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -137,11 +137,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner // This is a hack to make sure that an error dialog doesn't interfere with dismissing the refreshControl. // If the error dialog appears too closely to the call to endRefreshing, then the refreshControl never disappears. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - AccountManager.shared.refreshAll(errorHandler: ErrorHandler.present(self)) { - if AppDefaults.refreshClearsReadArticles { - self.coordinator.refreshTimeline(resetScroll: false) - } - } + appDelegate.manualRefresh(errorHandler: ErrorHandler.present(self)) } } diff --git a/iOS/RootSplitViewController.swift b/iOS/RootSplitViewController.swift index a30da310c..93a6e4629 100644 --- a/iOS/RootSplitViewController.swift +++ b/iOS/RootSplitViewController.swift @@ -91,7 +91,7 @@ class RootSplitViewController: UISplitViewController { } @objc func refresh(_ sender: Any?) { - AccountManager.shared.refreshAll(errorHandler: ErrorHandler.present(self)) + appDelegate.manualRefresh(errorHandler: ErrorHandler.present(self)) } @objc func goToToday(_ sender: Any?) { diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 5df9e65ab..d7c7da63e 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -61,7 +61,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { private var wasRootSplitViewControllerCollapsed = false private let fetchAndMergeArticlesQueue = CoalescingQueue(name: "Fetch and Merge Articles", interval: 0.5) - private let rebuildBackingStoresWithMergeQueue = CoalescingQueue(name: "Rebuild The Backing Stores by Merging", interval: 0.5) + private let rebuildBackingStoresWithMergeQueue = CoalescingQueue(name: "Rebuild The Backing Stores by Merging", interval: 1.0) private var fetchSerialNumber = 0 private let fetchRequestQueue = FetchRequestQueue() @@ -572,6 +572,15 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { fetchRequestQueue.cancelAllRequests() } + func refreshInterface() { + if isReadFeedsFiltered { + rebuildBackingStores() + } + if isReadArticlesFiltered && AppDefaults.refreshClearsReadArticles { + refreshTimeline(resetScroll: false) + } + } + func shadowNodesFor(section: Int) -> [Node] { return shadowTable[section] } diff --git a/iOS/SceneDelegate.swift b/iOS/SceneDelegate.swift index 6c6447e5d..af85dd81a 100644 --- a/iOS/SceneDelegate.swift +++ b/iOS/SceneDelegate.swift @@ -81,6 +81,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { coordinator.suspend() } + func refreshInterface() { + coordinator.refreshInterface() + } + } private extension SceneDelegate {