Fix timeline pagination when no displayable events

This commit is contained in:
ganfra 2020-07-08 15:51:00 +02:00
parent e8dbed1642
commit 3aabb17ea5
2 changed files with 6 additions and 3 deletions

View File

@ -349,7 +349,7 @@ internal class DefaultTimeline(
updateState(Timeline.Direction.FORWARDS) {
it.copy(
hasMoreInCache = firstBuiltEvent == null || firstBuiltEvent.displayIndex < firstCacheEvent?.displayIndex ?: Int.MIN_VALUE,
hasMoreInCache = firstBuiltEvent != null && firstBuiltEvent.displayIndex < firstCacheEvent?.displayIndex ?: Int.MIN_VALUE,
hasReachedEnd = chunkEntity?.isLastForward ?: false
)
}
@ -369,6 +369,9 @@ internal class DefaultTimeline(
private fun paginateInternal(startDisplayIndex: Int?,
direction: Timeline.Direction,
count: Int): Boolean {
if (count == 0) {
return false
}
updateState(direction) { it.copy(requestedPaginationCount = count, isPaginating = true) }
val builtCount = buildTimelineEvents(startDisplayIndex, direction, count.toLong())
val shouldFetchMore = builtCount < count && !hasReachedEnd(direction)

View File

@ -241,12 +241,12 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
chunksToDelete.add(it)
}
}
val shouldUpdateSummary = chunksToDelete.isNotEmpty() && currentChunk.isLastForward && direction == PaginationDirection.FORWARDS
chunksToDelete.forEach {
it.deleteOnCascade()
}
if (shouldUpdateSummary) {
val roomSummaryEntity = RoomSummaryEntity.getOrCreate(realm, roomId)
val shouldUpdateSummary = roomSummaryEntity.latestPreviewableEvent == null || (chunksToDelete.isNotEmpty() && currentChunk.isLastForward && direction == PaginationDirection.FORWARDS)
if (shouldUpdateSummary) {
val latestPreviewableEvent = TimelineEventEntity.latestEvent(
realm,
roomId,