From 6c4e404ba135eb755235e33d5196695dd3e55719 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Wed, 9 Mar 2022 17:56:02 +0100 Subject: [PATCH 1/3] Fix updating unread marker if not to latest chunk SetReadMarkerTask was not updating the read marker when both the old and the new fully read eventId weren't in the last chunk, even when the new one was after the first one. --- changelog.d/5481.bugfix | 1 + .../matrix/android/sdk/internal/database/query/ReadQueries.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog.d/5481.bugfix diff --git a/changelog.d/5481.bugfix b/changelog.d/5481.bugfix new file mode 100644 index 00000000000..64891b503c1 --- /dev/null +++ b/changelog.d/5481.bugfix @@ -0,0 +1 @@ +Fix sometimes read marker not properly updating diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadQueries.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadQueries.kt index 8cc99c3d2fd..cb98029aeb5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadQueries.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadQueries.kt @@ -94,7 +94,7 @@ internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration, val eventToCheckIndex = eventToCheck?.displayIndex ?: Int.MAX_VALUE eventToCheckIndex <= readMarkerIndex } else { - eventToCheckChunk?.isLastForward == false + eventToCheckChunk?.isLastForward == false && readMarkerChunk?.isLastForward == true } } } From 0564942b0cdf7699421cc9ba9583a9460d8bcaa1 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Thu, 10 Mar 2022 20:22:38 +0100 Subject: [PATCH 2/3] isReadMarkerMoreRecent(): use helper to properly compare chunks --- .../matrix/android/sdk/internal/database/query/ReadQueries.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadQueries.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadQueries.kt index cb98029aeb5..6c587dfcae8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadQueries.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadQueries.kt @@ -94,7 +94,7 @@ internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration, val eventToCheckIndex = eventToCheck?.displayIndex ?: Int.MAX_VALUE eventToCheckIndex <= readMarkerIndex } else { - eventToCheckChunk?.isLastForward == false && readMarkerChunk?.isLastForward == true + eventToCheckChunk != null && readMarkerChunk?.isMoreRecentThan(eventToCheckChunk) == true } } } From 6ba02629ec461c949d9e7400a630af703d82e6a8 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Fri, 11 Mar 2022 11:22:26 +0100 Subject: [PATCH 3/3] 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 289db9fa15b..8bec2a443c5 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