From fa4f02b9e1b7d34c03a6914efefc841a27d1202d Mon Sep 17 00:00:00 2001 From: Dominik Kapusta Date: Fri, 13 Oct 2023 09:49:27 +0200 Subject: [PATCH] Reset bookmarks sync timestamp after migrating to FFS favorites --- Core/SyncBookmarksAdapter.swift | 10 +++++++++- DuckDuckGo/AppDelegate.swift | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Core/SyncBookmarksAdapter.swift b/Core/SyncBookmarksAdapter.swift index 0bc525ca30..bf09938370 100644 --- a/Core/SyncBookmarksAdapter.swift +++ b/Core/SyncBookmarksAdapter.swift @@ -35,7 +35,11 @@ public final class SyncBookmarksAdapter { public private(set) var provider: BookmarksProvider? public let databaseCleaner: BookmarkDatabaseCleaner public let syncDidCompletePublisher: AnyPublisher - public let widgetRefreshCancellable: AnyCancellable + public var shouldResetBookmarksSyncTimestamp: Bool = false { + willSet { + assert(provider == nil, "Setting this value has no effect after provider has been instantiated") + } + } public init(database: CoreDataDatabase, favoritesDisplayModeStorage: FavoritesDisplayModeStoring) { self.database = database @@ -73,6 +77,9 @@ public final class SyncBookmarksAdapter { syncDidCompleteSubject.send() } ) + if shouldResetBookmarksSyncTimestamp { + provider.lastSyncTimestamp = nil + } syncErrorCancellable = provider.syncErrorPublisher .sink { error in @@ -116,6 +123,7 @@ public final class SyncBookmarksAdapter { private var syncDidCompleteSubject = PassthroughSubject() private var syncErrorCancellable: AnyCancellable? + private var widgetRefreshCancellable: AnyCancellable private let database: CoreDataDatabase private let favoritesDisplayModeStorage: FavoritesDisplayModeStoring } diff --git a/DuckDuckGo/AppDelegate.swift b/DuckDuckGo/AppDelegate.swift index 4e7d3c6de1..76a8cb0541 100644 --- a/DuckDuckGo/AppDelegate.swift +++ b/DuckDuckGo/AppDelegate.swift @@ -141,7 +141,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { DatabaseMigration.migrate(to: context) } - bookmarksDatabase.loadStore { context, error in + bookmarksDatabase.loadStore { [weak self] context, error in guard let context = context else { if let error = error { Pixel.fire(pixel: .bookmarksCouldNotLoadDatabase, @@ -164,6 +164,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { BookmarkUtils.migrateToFormFactorSpecificFavorites(byCopyingExistingTo: .mobile, in: context) if context.hasChanges { try context.save(onErrorFire: .bookmarksMigrationCouldNotPrepareMultipleFavoriteFolders) + self?.syncDataProviders.bookmarksAdapter.shouldResetBookmarksSyncTimestamp = true } } catch { Thread.sleep(forTimeInterval: 1)