fix: ensure secondary sort by id ascending when sorting by createdAt descending
When events share the same createdAt timestamp, the tiebreaker sort by id must be ascending to produce a stable, deterministic order. Fixed several locations that either had no secondary sort, used descending id sort, or used .reversed() which incorrectly flipped both sort directions. https://claude.ai/code/session_01RvuyPf1x9wLf2DCgsSXLGz
This commit is contained in:
+1
-1
@@ -53,7 +53,7 @@ object SearchResultFilter {
|
||||
}
|
||||
|
||||
// Sort by createdAt descending
|
||||
return result.sortedByDescending { it.createdAt }
|
||||
return result.sortedWith(compareByDescending<Event> { it.createdAt }.thenBy { it.id })
|
||||
}
|
||||
|
||||
fun isReply(event: Event): Boolean = event.kind == 1 && event.tags.any { it.size >= 2 && it[0] == "e" }
|
||||
|
||||
+3
-3
@@ -33,16 +33,16 @@ object SearchResultSorter {
|
||||
): List<Event> =
|
||||
when (order) {
|
||||
SearchSortOrder.NEWEST -> {
|
||||
events.sortedByDescending { it.createdAt }
|
||||
events.sortedWith(compareByDescending<Event> { it.createdAt }.thenBy { it.id })
|
||||
}
|
||||
|
||||
SearchSortOrder.OLDEST -> {
|
||||
events.sortedBy { it.createdAt }
|
||||
events.sortedWith(compareBy<Event> { it.createdAt }.thenBy { it.id })
|
||||
}
|
||||
|
||||
SearchSortOrder.RELEVANCE -> {
|
||||
if (searchText.isBlank()) {
|
||||
events.sortedByDescending { it.createdAt }
|
||||
events.sortedWith(compareByDescending<Event> { it.createdAt }.thenBy { it.id })
|
||||
} else {
|
||||
events.sortedByDescending { scoreEvent(it, searchText) }
|
||||
}
|
||||
|
||||
+1
-1
@@ -75,4 +75,4 @@ sealed class CardFeedState {
|
||||
*/
|
||||
val DefaultCardComparator: Comparator<Card> =
|
||||
compareByDescending<Card> { it.createdAt() }
|
||||
.thenByDescending { it.id() }
|
||||
.thenBy { it.id() }
|
||||
|
||||
Reference in New Issue
Block a user