Skip to content

Commit

Permalink
Match Safari bookmarks behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Feb 21, 2022
1 parent 2b04251 commit fc97ceb
Showing 2 changed files with 14 additions and 16 deletions.
6 changes: 2 additions & 4 deletions DuckDuckGo/Bookmarks/Model/BookmarkList.swift
Original file line number Diff line number Diff line change
@@ -51,9 +51,7 @@ struct BookmarkList {
}
}

// Reverse the order of favorites, such that new favorites appear at the top.
// This will be improved later with the filtering/sorting additions.
self.favoriteBookmarkURLsOrdered = favoriteKeysOrdered.reversed()
self.favoriteBookmarkURLsOrdered = favoriteKeysOrdered
self.allBookmarkURLsOrdered = keysOrdered
self.itemsDict = itemsDict
self.topLevelEntities = topLevelEntities
@@ -65,7 +63,7 @@ struct BookmarkList {
return
}

allBookmarkURLsOrdered.insert(bookmark.url, at: 0)
allBookmarkURLsOrdered.append(bookmark.url) // .insert(bookmark.url, at: 0)
itemsDict[bookmark.url] = bookmark
}

24 changes: 12 additions & 12 deletions DuckDuckGo/Bookmarks/Services/BookmarkStore.swift
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ final class LocalBookmarkStore: BookmarkStore {
fetchRequest = Bookmark.topLevelEntitiesFetchRequest()
}

fetchRequest.sortDescriptors = [NSSortDescriptor(key: #keyPath(BookmarkManagedObject.dateAdded), ascending: false)]
fetchRequest.sortDescriptors = [NSSortDescriptor(key: #keyPath(BookmarkManagedObject.dateAdded), ascending: true)]
fetchRequest.returnsObjectsAsFaults = false

do {
@@ -364,17 +364,6 @@ final class LocalBookmarkStore: BookmarkStore {

let allFolders = try context.fetch(BookmarkFolder.bookmarkFoldersFetchRequest())

if let otherBookmarks = bookmarks.topLevelFolders.otherBookmarks.children {
// Reverse the top level collection so that the order matches the imported bookmarks correctly.
let result = recursivelyCreateEntities(from: otherBookmarks.reversed(),
parent: nil,
existingBookmarkURLs: bookmarkURLs,
markBookmarksAsFavorite: false,
in: self.context)

total += result
}

let existingFavoritesFolder = allFolders.first { ($0.titleEncrypted as? String) == UserText.bookmarkImportImportedFavorites }
let favoritesFolder = existingFavoritesFolder ?? createFolder(titled: UserText.bookmarkImportImportedFavorites, in: self.context)

@@ -388,6 +377,17 @@ final class LocalBookmarkStore: BookmarkStore {
total += result
}

if let otherBookmarks = bookmarks.topLevelFolders.otherBookmarks.children {
// Reverse the top level collection so that the order matches the imported bookmarks correctly.
let result = recursivelyCreateEntities(from: otherBookmarks,
parent: nil,
existingBookmarkURLs: bookmarkURLs,
markBookmarksAsFavorite: false,
in: self.context)

total += result
}

try self.context.save()
let bookmarkCountAfterImport = try context.count(for: Bookmark.bookmarksFetchRequest())

0 comments on commit fc97ceb

Please sign in to comment.