From 6ba02629ec461c949d9e7400a630af703d82e6a8 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Fri, 11 Mar 2022 11:22:26 +0100 Subject: [PATCH] Fix ChunkEntity.isMoreRecentThan() if both chunks linked to last forward Imagine scenario: [this] -> [chunkToCheck] -> [lastForwardChunk] Then, both `isLastForward` checks will not return, and also the `chunkToCheck.doesNextChunksVerifyCondition { it == this }` will return false. Since both chunks are connected to the last forward chunk, `isMoreRecent()` will still return `true`, which is wrong in this case. So do not only check if chunkToCheck has this as any of the next chunks, but also the other way round. --- .../android/sdk/internal/database/helper/ChunkEntityHelper.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ChunkEntityHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ChunkEntityHelper.kt index 289db9fa15..8bec2a443c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ChunkEntityHelper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ChunkEntityHelper.kt @@ -223,6 +223,9 @@ internal fun ChunkEntity.isMoreRecentThan(chunkToCheck: ChunkEntity): Boolean { if (chunkToCheck.doesNextChunksVerifyCondition { it == this }) { return true } + if (this.doesNextChunksVerifyCondition { it == chunkToCheck }) { + return false + } // Otherwise check if this chunk is linked to last forward if (this.doesNextChunksVerifyCondition { it.isLastForward }) { return true