Merge pull request #5450 from SpiritCroc/fix-5448

Fix missing messages when forward paging with chunks > 50 messages
This commit is contained in:
Benoit Marty 2022-03-10 15:08:58 +01:00 committed by GitHub
commit 66f76fbea3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

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

@ -0,0 +1 @@
Fix missing messages when loading messages forwards

View file

@ -144,14 +144,14 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
val offsetCount = count - loadFromStorage.numberOfEvents val offsetCount = count - loadFromStorage.numberOfEvents
return if (direction == Timeline.Direction.FORWARDS && isLastForward.get()) { return if (offsetCount == 0) {
LoadMoreResult.SUCCESS
} else if (direction == Timeline.Direction.FORWARDS && isLastForward.get()) {
LoadMoreResult.REACHED_END LoadMoreResult.REACHED_END
} else if (direction == Timeline.Direction.BACKWARDS && isLastBackward.get()) { } else if (direction == Timeline.Direction.BACKWARDS && isLastBackward.get()) {
LoadMoreResult.REACHED_END LoadMoreResult.REACHED_END
} else if (timelineSettings.isThreadTimeline() && loadFromStorage.threadReachedEnd) { } else if (timelineSettings.isThreadTimeline() && loadFromStorage.threadReachedEnd) {
LoadMoreResult.REACHED_END LoadMoreResult.REACHED_END
} else if (offsetCount == 0) {
LoadMoreResult.SUCCESS
} else { } else {
delegateLoadMore(fetchOnServerIfNeeded, offsetCount, direction) delegateLoadMore(fetchOnServerIfNeeded, offsetCount, direction)
} }
@ -508,13 +508,18 @@ private fun RealmQuery<TimelineEventEntity>.offsets(
count: Int, count: Int,
startDisplayIndex: Int startDisplayIndex: Int
): RealmQuery<TimelineEventEntity> { ): RealmQuery<TimelineEventEntity> {
sort(TimelineEventEntityFields.DISPLAY_INDEX, Sort.DESCENDING) return if (direction == Timeline.Direction.BACKWARDS) {
if (direction == Timeline.Direction.BACKWARDS) {
lessThanOrEqualTo(TimelineEventEntityFields.DISPLAY_INDEX, startDisplayIndex) lessThanOrEqualTo(TimelineEventEntityFields.DISPLAY_INDEX, startDisplayIndex)
sort(TimelineEventEntityFields.DISPLAY_INDEX, Sort.DESCENDING)
limit(count.toLong())
} else { } else {
greaterThanOrEqualTo(TimelineEventEntityFields.DISPLAY_INDEX, startDisplayIndex) greaterThanOrEqualTo(TimelineEventEntityFields.DISPLAY_INDEX, startDisplayIndex)
// We need to sort ascending first so limit works in the right direction
sort(TimelineEventEntityFields.DISPLAY_INDEX, Sort.ASCENDING)
limit(count.toLong())
// Result is expected to be sorted descending
sort(TimelineEventEntityFields.DISPLAY_INDEX, Sort.DESCENDING)
} }
return limit(count.toLong())
} }
private fun Timeline.Direction.toPaginationDirection(): PaginationDirection { private fun Timeline.Direction.toPaginationDirection(): PaginationDirection {