Skip to content

Commit

Permalink
Ensure proper double linking of TimelineChunks
Browse files Browse the repository at this point in the history
We need both directions so getOffsetIndex() produces correct results in
all cases.
  • Loading branch information
SpiritCroc committed Mar 17, 2022
1 parent d1a77d2 commit 91259be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/5564.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix sometimes read marker not properly updating
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
isLastBackward.set(chunkEntity.isLastBackward)
}
if (changeSet.isFieldChanged(ChunkEntityFields.NEXT_CHUNK.`$`)) {
nextChunk = createTimelineChunk(chunkEntity.nextChunk)
nextChunk = createTimelineChunk(chunkEntity.nextChunk).also {
it?.prevChunk = this
}
nextChunkLatch?.complete(Unit)
}
if (changeSet.isFieldChanged(ChunkEntityFields.PREV_CHUNK.`$`)) {
prevChunk = createTimelineChunk(chunkEntity.prevChunk)
prevChunk = createTimelineChunk(chunkEntity.prevChunk).also {
it?.nextChunk = this
}
prevChunkLatch?.complete(Unit)
}
}
Expand Down Expand Up @@ -194,7 +198,9 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
when {
nextChunkEntity != null -> {
if (nextChunk == null) {
nextChunk = createTimelineChunk(nextChunkEntity)
nextChunk = createTimelineChunk(nextChunkEntity).also {
it?.prevChunk = this
}
}
nextChunk?.loadMore(offsetCount, direction, fetchFromServerIfNeeded) ?: LoadMoreResult.FAILURE
}
Expand All @@ -210,7 +216,9 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
when {
prevChunkEntity != null -> {
if (prevChunk == null) {
prevChunk = createTimelineChunk(prevChunkEntity)
prevChunk = createTimelineChunk(prevChunkEntity).also {
it?.nextChunk = this
}
}
prevChunk?.loadMore(offsetCount, direction, fetchFromServerIfNeeded) ?: LoadMoreResult.FAILURE
}
Expand Down

0 comments on commit 91259be

Please sign in to comment.