diff --git a/DuckDuckGo/AppDelegate/AppDelegate.swift b/DuckDuckGo/AppDelegate/AppDelegate.swift index ead4a26ade..7979c1f334 100644 --- a/DuckDuckGo/AppDelegate/AppDelegate.swift +++ b/DuckDuckGo/AppDelegate/AppDelegate.swift @@ -316,6 +316,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 bc052345ba..bd7f489e34 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 83fbca4159..a3a755df5a 100644 --- a/DuckDuckGo/Bookmarks/Services/LocalBookmarkStore.swift +++ b/DuckDuckGo/Bookmarks/Services/LocalBookmarkStore.swift @@ -59,6 +59,7 @@ final class LocalBookmarkStore: BookmarkStore { } private(set) var favoritesDisplayMode: FavoritesDisplayMode + private(set) var didMigrateToFormFactorSpecificFavorites: Bool = false private let contextProvider: () -> NSManagedObjectContext @@ -214,6 +215,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 86067e5234..d515e5edf7 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") + } + } init( database: CoreDataDatabase, @@ -63,6 +68,9 @@ final class SyncBookmarksAdapter { metadataStore: metadataStore, syncDidUpdateData: LocalBookmarkManager.shared.loadBookmarks ) + if shouldResetBookmarksSyncTimestamp { + provider.lastSyncTimestamp = nil + } syncErrorCancellable = provider.syncErrorPublisher .sink { error in 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 }