Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset bookmarks sync timestamp after migrating to FFS favorites #1755

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DuckDuckGo/AppDelegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/Bookmarks/Model/BookmarkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<BookmarkList?>.Publisher { get }
Expand Down Expand Up @@ -81,6 +82,10 @@ final class LocalBookmarkManager: BookmarkManager {
@Published private(set) var list: BookmarkList?
var listPublisher: Published<BookmarkList?>.Publisher { $list }

var didMigrateToFormFactorSpecificFavorites: Bool {
bookmarkStore.didMigrateToFormFactorSpecificFavorites
}

private lazy var bookmarkStore: BookmarkStore = LocalBookmarkStore(bookmarkDatabase: BookmarkDatabase.shared)
private lazy var faviconManagement: FaviconManagement = FaviconManager.shared

Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Bookmarks/Services/BookmarkStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ protocol BookmarkStore {
func importBookmarks(_ bookmarks: ImportedBookmarks, source: BookmarkImportSource) -> BookmarkImportResult

func handleFavoritesAfterDisablingSync()
var didMigrateToFormFactorSpecificFavorites: Bool { get }
}
2 changes: 2 additions & 0 deletions DuckDuckGo/Bookmarks/Services/LocalBookmarkStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ final class LocalBookmarkStore: BookmarkStore {
}

private(set) var favoritesDisplayMode: FavoritesDisplayMode
private(set) var didMigrateToFormFactorSpecificFavorites: Bool = false

private let contextProvider: () -> NSManagedObjectContext

Expand Down Expand Up @@ -215,6 +216,7 @@ final class LocalBookmarkStore: BookmarkStore {

if context.hasChanges {
try context.save(onErrorFire: .bookmarksMigrationCouldNotPrepareMultipleFavoriteFolders)
didMigrateToFormFactorSpecificFavorites = true
}
} catch {
Thread.sleep(forTimeInterval: 1)
Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/Sync/SyncBookmarksAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions UnitTests/Bookmarks/Services/BookmarkStoreMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,5 @@ final class BookmarkStoreMock: BookmarkStore {

func applyFavoritesDisplayMode(_ configuration: FavoritesDisplayMode) {}
func handleFavoritesAfterDisablingSync() {}
var didMigrateToFormFactorSpecificFavorites: Bool = false
}
2 changes: 2 additions & 0 deletions UnitTests/HomePage/Mocks/MockBookmarkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class MockBookmarkManager: BookmarkManager {

func handleFavoritesAfterDisablingSync() {}

var didMigrateToFormFactorSpecificFavorites: Bool = false

@Published var list: BookmarkList?

var listPublisher: Published<BookmarkList?>.Publisher { $list }
Expand Down
Loading