Skip to content

Commit

Permalink
improve duplicate detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mopsalarm committed Jan 23, 2024
1 parent a22ab80 commit 4043958
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ class BookmarkService(
*/
fun observe(): Flow<List<Bookmark>> {
val comparator = compareBy<Bookmark> { !it.trending }.thenBy { it.title.lowercase(Locale.getDefault()) }
return bookmarks.map { it.sortedWith(comparator) }.distinctUntilChanged()
return bookmarks
.map { bookmarks -> bookmarks.sortedWith(comparator) }
.map { bookmarks -> bookmarks.distinctBy { it.title.trim() } }
.distinctUntilChanged()
}

/**
Expand Down Expand Up @@ -149,7 +152,7 @@ class BookmarkService(
val local = bookmarks.value.filter { it._link == null || it.notSyncable }

// and merge them together, with the local ones winning.
val merged = (local + update).distinctBy { it.title.lowercase(Locale.getDefault()) }
val merged = (local + update).distinctBy { it.title.lowercase(Locale.getDefault()).trim() }

bookmarks.value = merged
}
Expand Down Expand Up @@ -230,7 +233,7 @@ class BookmarkService(
val canEdit: Boolean get() = bookmarkSyncService.canChange

private fun Bookmark.hasTitle(title: String): Boolean {
return this.title.equals(title, ignoreCase = false)
return this.title.trim().equals(title.trim(), ignoreCase = false)
}

private val Bookmark.syncable: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BookmarkSyncService(private val api: Api, private val userService: UserSer
* We might have better handling for those bookmarks in the app
*/
private fun isAppSpecialCategory(bookmark: Api.Bookmark): Boolean {
val name = bookmark.name.lowercase(Locale.GERMAN)
val name = bookmark.name.lowercase(Locale.GERMAN).trim()
return name == "best of" || name == "kontrovers" || name == "wichteln"
}

Expand Down

0 comments on commit 4043958

Please sign in to comment.