Ensure proper double linking of TimelineChunks

We need both directions so getOffsetIndex() produces correct results in
all cases.
This commit is contained in:
SpiritCroc 2022-03-17 11:02:32 +01:00
parent d1a77d2eca
commit 91259bef40
2 changed files with 13 additions and 4 deletions

1
changelog.d/5564.bugfix Normal file
View file

@ -0,0 +1 @@
Fix sometimes read marker not properly updating

View file

@ -83,11 +83,15 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
isLastBackward.set(chunkEntity.isLastBackward) isLastBackward.set(chunkEntity.isLastBackward)
} }
if (changeSet.isFieldChanged(ChunkEntityFields.NEXT_CHUNK.`$`)) { if (changeSet.isFieldChanged(ChunkEntityFields.NEXT_CHUNK.`$`)) {
nextChunk = createTimelineChunk(chunkEntity.nextChunk) nextChunk = createTimelineChunk(chunkEntity.nextChunk).also {
it?.prevChunk = this
}
nextChunkLatch?.complete(Unit) nextChunkLatch?.complete(Unit)
} }
if (changeSet.isFieldChanged(ChunkEntityFields.PREV_CHUNK.`$`)) { if (changeSet.isFieldChanged(ChunkEntityFields.PREV_CHUNK.`$`)) {
prevChunk = createTimelineChunk(chunkEntity.prevChunk) prevChunk = createTimelineChunk(chunkEntity.prevChunk).also {
it?.nextChunk = this
}
prevChunkLatch?.complete(Unit) prevChunkLatch?.complete(Unit)
} }
} }
@ -194,7 +198,9 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
when { when {
nextChunkEntity != null -> { nextChunkEntity != null -> {
if (nextChunk == null) { if (nextChunk == null) {
nextChunk = createTimelineChunk(nextChunkEntity) nextChunk = createTimelineChunk(nextChunkEntity).also {
it?.prevChunk = this
}
} }
nextChunk?.loadMore(offsetCount, direction, fetchFromServerIfNeeded) ?: LoadMoreResult.FAILURE nextChunk?.loadMore(offsetCount, direction, fetchFromServerIfNeeded) ?: LoadMoreResult.FAILURE
} }
@ -210,7 +216,9 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
when { when {
prevChunkEntity != null -> { prevChunkEntity != null -> {
if (prevChunk == null) { if (prevChunk == null) {
prevChunk = createTimelineChunk(prevChunkEntity) prevChunk = createTimelineChunk(prevChunkEntity).also {
it?.nextChunk = this
}
} }
prevChunk?.loadMore(offsetCount, direction, fetchFromServerIfNeeded) ?: LoadMoreResult.FAILURE prevChunk?.loadMore(offsetCount, direction, fetchFromServerIfNeeded) ?: LoadMoreResult.FAILURE
} }