Timeline: check for create event to hide loader

This commit is contained in:
ganfra 2021-12-03 18:39:04 +01:00
parent 8ca60eadbb
commit 3217277bc4
2 changed files with 12 additions and 20 deletions

View File

@ -83,18 +83,21 @@ interface Timeline {
* The latest event is the first in the list
* @param snapshot the most up to date snapshot
*/
fun onTimelineUpdated(snapshot: List<TimelineEvent>)
fun onTimelineUpdated(snapshot: List<TimelineEvent>) = Unit
/**
* Called whenever an error we can't recover from occurred
*/
fun onTimelineFailure(throwable: Throwable)
fun onTimelineFailure(throwable: Throwable) = Unit
/**
* Called when new events come through the sync
*/
fun onNewTimelineEvents(eventIds: List<String>)
fun onNewTimelineEvents(eventIds: List<String>) = Unit
/**
* Called when the pagination state has changed in one direction
*/
fun onStateUpdated(direction: Direction, state: PaginationState) = Unit
}

View File

@ -174,6 +174,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
private var inSubmitList: Boolean = false
private var hasReachedInvite: Boolean = false
private var hasUTD: Boolean = false
private var hasReachedCreateEvent: Boolean = false
private var positionOfReadMarker: Int? = null
private var partialState: PartialState = PartialState()
@ -286,7 +287,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
return
}
// Avoid displaying two loaders if there is no elements between them
val showBackwardsLoader = !showingForwardLoader || timelineModels.isNotEmpty()
val showBackwardsLoader = (!showingForwardLoader || timelineModels.isNotEmpty()) && !hasReachedCreateEvent
// We can hide the loader but still add the item to controller so it can trigger backwards pagination
LoadingItem_()
.id("backward_loading_item_$timestamp")
@ -301,22 +302,6 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
submitSnapshot(snapshot)
}
override fun onTimelineFailure(throwable: Throwable) {
// no-op, already handled
}
override fun onNewTimelineEvents(eventIds: List<String>) {
// no-op, already handled
}
override fun onStateUpdated(direction: Timeline.Direction, state: Timeline.PaginationState) {
if (!state.hasMoreToLoad) {
backgroundHandler.post {
requestDelayedModelBuild(0)
}
}
}
private fun submitSnapshot(newSnapshot: List<TimelineEvent>) {
backgroundHandler.post {
inSubmitList = true
@ -471,10 +456,14 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
private fun preprocessReverseEvents() {
receiptsByEvent.clear()
timelineEventsGroups.clear()
hasReachedCreateEvent = false
val itr = currentSnapshot.listIterator(currentSnapshot.size)
var lastShownEventId: String? = null
while (itr.hasPrevious()) {
val event = itr.previous()
if (!hasReachedCreateEvent && event.root.type == EventType.STATE_ROOM_CREATE) {
hasReachedCreateEvent = true
}
timelineEventsGroups.addOrIgnore(event)
val currentReadReceipts = ArrayList(event.readReceipts).filter {
it.user.userId != session.myUserId