Fixes thread ordering issues with two notes with the same idHex

pull/572/head
Vitor Pamplona 2023-09-02 12:46:24 -04:00
rodzic d3fa05a4df
commit d13e8bacec
2 zmienionych plików z 4 dodań i 3 usunięć

Wyświetl plik

@ -142,7 +142,7 @@ open class Note(val idHex: String) {
* This method caches signatures during each execution to avoid recalculation in longer threads * This method caches signatures during each execution to avoid recalculation in longer threads
*/ */
fun replyLevelSignature( fun replyLevelSignature(
eventsToConsider: Set<Note>, eventsToConsider: Set<HexKey>,
cachedSignatures: MutableMap<Note, LevelSignature>, cachedSignatures: MutableMap<Note, LevelSignature>,
account: User, account: User,
accountFollowingSet: Set<String>, accountFollowingSet: Set<String>,
@ -159,7 +159,7 @@ open class Note(val idHex: String) {
val parent = ( val parent = (
replyTo replyTo
.filter { it in eventsToConsider } // This forces the signature to be based on a branch, avoiding two roots .filter { it.idHex in eventsToConsider } // This forces the signature to be based on a branch, avoiding two roots
.map { .map {
cachedSignatures[it] ?: it.replyLevelSignature( cachedSignatures[it] ?: it.replyLevelSignature(
eventsToConsider, eventsToConsider,

Wyświetl plik

@ -18,11 +18,12 @@ class ThreadFeedFilter(val account: Account, val noteId: String) : FeedFilter<No
val cachedSignatures: MutableMap<Note, Note.LevelSignature> = mutableMapOf() val cachedSignatures: MutableMap<Note, Note.LevelSignature> = mutableMapOf()
val followingSet = account.selectedUsersFollowList(KIND3_FOLLOWS) ?: emptySet() val followingSet = account.selectedUsersFollowList(KIND3_FOLLOWS) ?: emptySet()
val eventsToWatch = ThreadAssembler().findThreadFor(noteId) val eventsToWatch = ThreadAssembler().findThreadFor(noteId)
val eventsInHex = eventsToWatch.map { it.idHex }.toSet()
val now = TimeUtils.now() val now = TimeUtils.now()
// Currently orders by date of each event, descending, at each level of the reply stack // Currently orders by date of each event, descending, at each level of the reply stack
val order = compareByDescending<Note> { val order = compareByDescending<Note> {
it.replyLevelSignature(eventsToWatch, cachedSignatures, account.userProfile(), followingSet, now).signature it.replyLevelSignature(eventsInHex, cachedSignatures, account.userProfile(), followingSet, now).signature
} }
return eventsToWatch.sortedWith(order) return eventsToWatch.sortedWith(order)