mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +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 methods *****************************************************************************
|
||||||
|
|
||||||
private fun hasMoreInCache(direction: Timeline.Direction): Boolean {
|
private fun hasMoreInCache(direction: Timeline.Direction): Boolean {
|
||||||
val localRealm = Realm.getInstance(realmConfiguration)
|
return Realm.getInstance(realmConfiguration).use { localRealm ->
|
||||||
val timelineEventEntity = buildEventQuery(localRealm).findFirst(direction) ?: return false
|
val timelineEventEntity = buildEventQuery(localRealm).findFirst(direction)
|
||||||
val hasMoreInCache = if (direction == Timeline.Direction.FORWARDS) {
|
?: return false
|
||||||
|
if (direction == Timeline.Direction.FORWARDS) {
|
||||||
|
if (findCurrentChunk(localRealm)?.isLastForward == true) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
val firstEvent = builtEvents.firstOrNull() ?: return true
|
val firstEvent = builtEvents.firstOrNull() ?: return true
|
||||||
firstEvent.displayIndex < timelineEventEntity.root!!.displayIndex
|
firstEvent.displayIndex < timelineEventEntity.root!!.displayIndex
|
||||||
} else {
|
} else {
|
||||||
val lastEvent = builtEvents.lastOrNull() ?: return true
|
val lastEvent = builtEvents.lastOrNull() ?: return true
|
||||||
lastEvent.displayIndex > timelineEventEntity.root!!.displayIndex
|
lastEvent.displayIndex > timelineEventEntity.root!!.displayIndex
|
||||||
}
|
}
|
||||||
localRealm.close()
|
}
|
||||||
return hasMoreInCache
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hasReachedEnd(direction: Timeline.Direction): Boolean {
|
private fun hasReachedEnd(direction: Timeline.Direction): Boolean {
|
||||||
val localRealm = Realm.getInstance(realmConfiguration)
|
return Realm.getInstance(realmConfiguration).use { localRealm ->
|
||||||
val currentChunk = findCurrentChunk(localRealm) ?: return false
|
val currentChunk = findCurrentChunk(localRealm) ?: return false
|
||||||
val hasReachedEnd = if (direction == Timeline.Direction.FORWARDS) {
|
if (direction == Timeline.Direction.FORWARDS) {
|
||||||
currentChunk.isLastForward
|
currentChunk.isLastForward
|
||||||
} else {
|
} else {
|
||||||
val eventEntity = buildEventQuery(localRealm).findFirst(direction)
|
val eventEntity = buildEventQuery(localRealm).findFirst(direction)
|
||||||
currentChunk.isLastBackward || eventEntity?.root?.type == EventType.STATE_ROOM_CREATE
|
currentChunk.isLastBackward || eventEntity?.root?.type == EventType.STATE_ROOM_CREATE
|
||||||
}
|
}
|
||||||
localRealm.close()
|
}
|
||||||
return hasReachedEnd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue