mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Fix timeline forward loader showing when sending events
This commit is contained in:
parent
585f0ba4b7
commit
7f09e64d63
1 changed files with 21 additions and 19 deletions
|
@ -278,30 +278,32 @@ internal class DefaultTimeline(
|
|||
// Private methods *****************************************************************************
|
||||
|
||||
private fun hasMoreInCache(direction: Timeline.Direction): Boolean {
|
||||
val localRealm = Realm.getInstance(realmConfiguration)
|
||||
val timelineEventEntity = buildEventQuery(localRealm).findFirst(direction) ?: return false
|
||||
val hasMoreInCache = if (direction == Timeline.Direction.FORWARDS) {
|
||||
val firstEvent = builtEvents.firstOrNull() ?: return true
|
||||
firstEvent.displayIndex < timelineEventEntity.root!!.displayIndex
|
||||
} else {
|
||||
val lastEvent = builtEvents.lastOrNull() ?: return true
|
||||
lastEvent.displayIndex > timelineEventEntity.root!!.displayIndex
|
||||
return Realm.getInstance(realmConfiguration).use { localRealm ->
|
||||
val timelineEventEntity = buildEventQuery(localRealm).findFirst(direction)
|
||||
?: return false
|
||||
if (direction == Timeline.Direction.FORWARDS) {
|
||||
if (findCurrentChunk(localRealm)?.isLastForward == true) {
|
||||
return false
|
||||
}
|
||||
val firstEvent = builtEvents.firstOrNull() ?: return true
|
||||
firstEvent.displayIndex < timelineEventEntity.root!!.displayIndex
|
||||
} else {
|
||||
val lastEvent = builtEvents.lastOrNull() ?: return true
|
||||
lastEvent.displayIndex > timelineEventEntity.root!!.displayIndex
|
||||
}
|
||||
}
|
||||
localRealm.close()
|
||||
return hasMoreInCache
|
||||
}
|
||||
|
||||
private fun hasReachedEnd(direction: Timeline.Direction): Boolean {
|
||||
val localRealm = Realm.getInstance(realmConfiguration)
|
||||
val currentChunk = findCurrentChunk(localRealm) ?: return false
|
||||
val hasReachedEnd = if (direction == Timeline.Direction.FORWARDS) {
|
||||
currentChunk.isLastForward
|
||||
} else {
|
||||
val eventEntity = buildEventQuery(localRealm).findFirst(direction)
|
||||
currentChunk.isLastBackward || eventEntity?.root?.type == EventType.STATE_ROOM_CREATE
|
||||
return Realm.getInstance(realmConfiguration).use { localRealm ->
|
||||
val currentChunk = findCurrentChunk(localRealm) ?: return false
|
||||
if (direction == Timeline.Direction.FORWARDS) {
|
||||
currentChunk.isLastForward
|
||||
} else {
|
||||
val eventEntity = buildEventQuery(localRealm).findFirst(direction)
|
||||
currentChunk.isLastBackward || eventEntity?.root?.type == EventType.STATE_ROOM_CREATE
|
||||
}
|
||||
}
|
||||
localRealm.close()
|
||||
return hasReachedEnd
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue