mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-07 06:23:55 +01:00
Timeline: fix hasReachedEnd
This commit is contained in:
parent
a1fdd31b68
commit
92a37f15d4
@ -111,8 +111,7 @@ internal class LoadTimelineStrategy(
|
||||
}
|
||||
|
||||
override fun onNewTimelineEvents(roomId: String, eventIds: List<String>) {
|
||||
super.onNewTimelineEvents(roomId, eventIds)
|
||||
if (mode == Mode.Live && roomId == this@LoadTimelineStrategy.roomId) {
|
||||
if (roomId == this@LoadTimelineStrategy.roomId && hasReachedLastForward()) {
|
||||
dependencies.onNewTimelineEvents(eventIds)
|
||||
}
|
||||
}
|
||||
@ -178,7 +177,7 @@ internal class LoadTimelineStrategy(
|
||||
}
|
||||
|
||||
private fun buildSendingEvents(): List<TimelineEvent> {
|
||||
return if (timelineChunk?.hasReachedLastForward().orFalse()) {
|
||||
return if (hasReachedLastForward()) {
|
||||
sendingEventsDataSource.buildSendingEvents()
|
||||
} else {
|
||||
emptyList()
|
||||
@ -195,6 +194,10 @@ internal class LoadTimelineStrategy(
|
||||
}
|
||||
}
|
||||
|
||||
private fun hasReachedLastForward(): Boolean{
|
||||
return timelineChunk?.hasReachedLastForward().orFalse()
|
||||
}
|
||||
|
||||
private fun RealmResults<ChunkEntity>.createTimelineChunk(): TimelineChunk? {
|
||||
return firstOrNull()?.let {
|
||||
return TimelineChunk(
|
||||
|
@ -28,10 +28,12 @@ import org.matrix.android.sdk.api.session.room.timeline.Timeline
|
||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
||||
import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper
|
||||
import org.matrix.android.sdk.internal.database.model.ChunkEntity
|
||||
import org.matrix.android.sdk.internal.database.model.ChunkEntityFields
|
||||
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
|
||||
import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields
|
||||
import timber.log.Timber
|
||||
import java.util.Collections
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
/**
|
||||
* This is the value used to fetch on server. It's better to make constant as otherwise we can have weird chunks with disparate and small chunk of data.
|
||||
@ -54,8 +56,13 @@ internal class TimelineChunk constructor(private val chunkEntity: ChunkEntity,
|
||||
private val initialEventId: String?,
|
||||
private val onBuiltEvents: () -> Unit) {
|
||||
|
||||
private val isLastForward = AtomicBoolean(chunkEntity.isLastForward)
|
||||
|
||||
private val chunkObjectListener = RealmObjectChangeListener<ChunkEntity> { _, changeSet ->
|
||||
Timber.v("on chunk (${chunkEntity.identifier()}) changed: ${changeSet?.changedFields?.joinToString(",")}")
|
||||
if(changeSet?.isFieldChanged(ChunkEntityFields.IS_LAST_FORWARD).orFalse()){
|
||||
isLastForward.set(chunkEntity.isLastForward)
|
||||
}
|
||||
}
|
||||
|
||||
private val timelineEventCollectionListener = OrderedRealmCollectionChangeListener { results: RealmResults<TimelineEventEntity>, changeSet: OrderedCollectionChangeSet ->
|
||||
@ -77,7 +84,7 @@ internal class TimelineChunk constructor(private val chunkEntity: ChunkEntity,
|
||||
}
|
||||
|
||||
fun hasReachedLastForward(): Boolean {
|
||||
return if (chunkEntity.isLastForward) {
|
||||
return if (isLastForward.get()) {
|
||||
true
|
||||
} else {
|
||||
nextChunk?.hasReachedLastForward().orFalse()
|
||||
|
Loading…
x
Reference in New Issue
Block a user