From 967bff063bba25ebbc4b146d1d93f6f02dbebcb5 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 25 Dec 2022 09:59:35 -0500 Subject: [PATCH] Tweak iCloud timeline sync --- .../Timeline/TimelineViewController.swift | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index cd3a84f9..251bf1c9 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -134,7 +134,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro } .debounce(for: .milliseconds(500), scheduler: DispatchQueue.main) .sink { [unowned self] _ in - _ = promptToSyncPositionIfNecessary() + _ = syncPositionIfNecessary(alwaysPrompt: true) } .store(in: &cancellables) } @@ -225,11 +225,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro } } } else { - if promptToSyncPositionIfNecessary() { - // no-op - } else { - checkPresentIfEnoughTimeElapsed() - } + syncAndCheckPresentIfEnoughTimeElapsed() } } @@ -448,11 +444,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro view.window?.windowScene == scene else { return } - if promptToSyncPositionIfNecessary() { - // no-op - } else { - checkPresentIfEnoughTimeElapsed() - } + syncAndCheckPresentIfEnoughTimeElapsed() } @objc private func sceneDidEnterBackground(_ notification: Foundation.Notification) { @@ -465,7 +457,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro saveState() } - private func promptToSyncPositionIfNecessary() -> Bool { + private func syncPositionIfNecessary(alwaysPrompt: Bool) -> Bool { guard persistsState, let timelinePosition = mastodonController.persistentContainer.getTimelinePosition(timeline: timeline) else { return false @@ -491,16 +483,20 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro guard timelinePosition.centerStatusID != centerVisibleStatusID else { return false } - var config = ToastConfiguration(title: "Sync Position") - config.edge = .top - config.dismissAutomaticallyAfter = 5 - config.systemImageName = "arrow.triangle.2.circlepath" - config.action = { [unowned self] toast in - toast.dismissToast(animated: true) + if !alwaysPrompt { _ = self.restoreState() + } else { + var config = ToastConfiguration(title: "Sync Position") + config.edge = .top + config.dismissAutomaticallyAfter = 5 + config.systemImageName = "arrow.triangle.2.circlepath" + config.action = { [unowned self] toast in + toast.dismissToast(animated: true) + _ = self.restoreState() + } + showToast(configuration: config, animated: true) + UIAccessibility.post(notification: .announcement, argument: "Synced Position Updated") } - showToast(configuration: config, animated: true) - UIAccessibility.post(notification: .announcement, argument: "Synced Position Updated") return true } @@ -529,14 +525,18 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro } } - private func checkPresentIfEnoughTimeElapsed() { + private func syncAndCheckPresentIfEnoughTimeElapsed() { guard let disappearedAt, -disappearedAt.timeIntervalSinceNow > 60 * 60 /* 1 hour */ else { return } self.disappearedAt = nil - Task { - await checkPresent(jumpImmediately: false) + if syncPositionIfNecessary(alwaysPrompt: false) { + // no-op + } else { + Task { + await checkPresent(jumpImmediately: false) + } } }