diff --git a/DuckDuckGo/AppDelegate/AppDelegate.swift b/DuckDuckGo/AppDelegate/AppDelegate.swift index ebfda31f2d..74ee5e66c6 100644 --- a/DuckDuckGo/AppDelegate/AppDelegate.swift +++ b/DuckDuckGo/AppDelegate/AppDelegate.swift @@ -314,6 +314,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel let environment = defaultEnvironment #endif let syncDataProviders = SyncDataProviders(bookmarksDatabase: BookmarkDatabase.shared.db) + if bookmarksManager.didMigrateToFormFactorSpecificFavorites { + syncDataProviders.bookmarksAdapter.shouldResetBookmarksSyncTimestamp = true + } let syncService = DDGSync(dataProvidersSource: syncDataProviders, errorEvents: SyncErrorHandler(), log: OSLog.sync, environment: environment) syncService.initializeIfNeeded() syncDataProviders.setUpDatabaseCleaners(syncService: syncService) diff --git a/DuckDuckGo/Bookmarks/Model/BookmarkManager.swift b/DuckDuckGo/Bookmarks/Model/BookmarkManager.swift index 5326405074..bbcad8d6bb 100644 --- a/DuckDuckGo/Bookmarks/Model/BookmarkManager.swift +++ b/DuckDuckGo/Bookmarks/Model/BookmarkManager.swift @@ -46,6 +46,7 @@ protocol BookmarkManager: AnyObject { func importBookmarks(_ bookmarks: ImportedBookmarks, source: BookmarkImportSource) -> BookmarkImportResult func handleFavoritesAfterDisablingSync() + var didMigrateToFormFactorSpecificFavorites: Bool { get } // Wrapper definition in a protocol is not supported yet var listPublisher: Published.Publisher { get } @@ -81,6 +82,10 @@ final class LocalBookmarkManager: BookmarkManager { @Published private(set) var list: BookmarkList? var listPublisher: Published.Publisher { $list } + var didMigrateToFormFactorSpecificFavorites: Bool { + bookmarkStore.didMigrateToFormFactorSpecificFavorites + } + private lazy var bookmarkStore: BookmarkStore = LocalBookmarkStore(bookmarkDatabase: BookmarkDatabase.shared) private lazy var faviconManagement: FaviconManagement = FaviconManager.shared diff --git a/DuckDuckGo/Bookmarks/Services/BookmarkStore.swift b/DuckDuckGo/Bookmarks/Services/BookmarkStore.swift index 9f1ae6c010..2babd05dff 100644 --- a/DuckDuckGo/Bookmarks/Services/BookmarkStore.swift +++ b/DuckDuckGo/Bookmarks/Services/BookmarkStore.swift @@ -60,4 +60,5 @@ protocol BookmarkStore { func importBookmarks(_ bookmarks: ImportedBookmarks, source: BookmarkImportSource) -> BookmarkImportResult func handleFavoritesAfterDisablingSync() + var didMigrateToFormFactorSpecificFavorites: Bool { get } } diff --git a/DuckDuckGo/Bookmarks/Services/LocalBookmarkStore.swift b/DuckDuckGo/Bookmarks/Services/LocalBookmarkStore.swift index c6c378c572..d9600852ec 100644 --- a/DuckDuckGo/Bookmarks/Services/LocalBookmarkStore.swift +++ b/DuckDuckGo/Bookmarks/Services/LocalBookmarkStore.swift @@ -60,6 +60,7 @@ final class LocalBookmarkStore: BookmarkStore { } private(set) var favoritesDisplayMode: FavoritesDisplayMode + private(set) var didMigrateToFormFactorSpecificFavorites: Bool = false private let contextProvider: () -> NSManagedObjectContext @@ -215,6 +216,7 @@ final class LocalBookmarkStore: BookmarkStore { if context.hasChanges { try context.save(onErrorFire: .bookmarksMigrationCouldNotPrepareMultipleFavoriteFolders) + didMigrateToFormFactorSpecificFavorites = true } } catch { Thread.sleep(forTimeInterval: 1) diff --git a/DuckDuckGo/Sync/SyncBookmarksAdapter.swift b/DuckDuckGo/Sync/SyncBookmarksAdapter.swift index 12fc4a6774..b9cd8cbcbc 100644 --- a/DuckDuckGo/Sync/SyncBookmarksAdapter.swift +++ b/DuckDuckGo/Sync/SyncBookmarksAdapter.swift @@ -27,6 +27,11 @@ final class SyncBookmarksAdapter { private(set) var provider: BookmarksProvider? let databaseCleaner: BookmarkDatabaseCleaner + var shouldResetBookmarksSyncTimestamp: Bool = false { + willSet { + assert(provider == nil, "Setting this value has no effect after provider has been instantiated") + } + } @UserDefaultsWrapper(key: .syncBookmarksPaused, defaultValue: false) private var isSyncBookmarksPaused: Bool { @@ -72,6 +77,10 @@ final class SyncBookmarksAdapter { self?.isSyncBookmarksPaused = false } + if shouldResetBookmarksSyncTimestamp { + provider.lastSyncTimestamp = nil + } + syncErrorCancellable = provider.syncErrorPublisher .sink { [weak self] error in switch error { diff --git a/UnitTests/Bookmarks/Services/BookmarkStoreMock.swift b/UnitTests/Bookmarks/Services/BookmarkStoreMock.swift index 7e5265b12e..e3573c717b 100644 --- a/UnitTests/Bookmarks/Services/BookmarkStoreMock.swift +++ b/UnitTests/Bookmarks/Services/BookmarkStoreMock.swift @@ -111,4 +111,5 @@ final class BookmarkStoreMock: BookmarkStore { func applyFavoritesDisplayMode(_ configuration: FavoritesDisplayMode) {} func handleFavoritesAfterDisablingSync() {} + var didMigrateToFormFactorSpecificFavorites: Bool = false } diff --git a/UnitTests/HomePage/Mocks/MockBookmarkManager.swift b/UnitTests/HomePage/Mocks/MockBookmarkManager.swift index 60bda955c3..886517c90f 100644 --- a/UnitTests/HomePage/Mocks/MockBookmarkManager.swift +++ b/UnitTests/HomePage/Mocks/MockBookmarkManager.swift @@ -87,6 +87,8 @@ class MockBookmarkManager: BookmarkManager { func handleFavoritesAfterDisablingSync() {} + var didMigrateToFormFactorSpecificFavorites: Bool = false + @Published var list: BookmarkList? var listPublisher: Published.Publisher { $list }