Timeline: just some renaming + constant

This commit is contained in:
ganfra 2021-11-03 19:02:58 +01:00
parent 52d0da7053
commit a1fdd31b68
2 changed files with 11 additions and 9 deletions

View File

@ -29,7 +29,6 @@ import kotlinx.coroutines.withContext
import okhttp3.internal.closeQuietly
import org.matrix.android.sdk.api.extensions.tryOrNull
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.session.room.membership.LoadRoomMembersTask
import org.matrix.android.sdk.internal.session.sync.handler.room.ReadReceiptHandler
@ -81,7 +80,7 @@ internal class DefaultTimeline internal constructor(private val roomId: String,
onNewTimelineEvents = this::onNewTimelineEvents
)
private var strategy: LoadTimelineStrategy = buildStrategy(LoadTimelineStrategy.Mode.Default)
private var strategy: LoadTimelineStrategy = buildStrategy(LoadTimelineStrategy.Mode.Live)
override val isLive: Boolean
get() = !getPaginationState(Timeline.Direction.FORWARDS).hasMoreToLoad
@ -191,7 +190,7 @@ internal class DefaultTimeline internal constructor(private val roomId: String,
}
strategy.onStop()
strategy = if (eventId == null) {
buildStrategy(LoadTimelineStrategy.Mode.Default)
buildStrategy(LoadTimelineStrategy.Mode.Live)
} else {
buildStrategy(LoadTimelineStrategy.Mode.Permalink(eventId))
}

View File

@ -33,11 +33,14 @@ import java.util.concurrent.atomic.AtomicReference
/**
* This class is responsible for keeping an instance of chunkEntity and timelineChunk according to the strategy.
* There is 2 different mode: Default and Permalink.
* In Default, we will query for the live chunk (isLastForward = true).
* There is 2 different mode: Live and Permalink.
* In Live, we will query for the live chunk (isLastForward = true).
* In Permalink, we will query for the chunk including the eventId we are looking for.
* Once we got a ChunkEntity we wrap it with TimelineChunk class so we dispatch any methods for loading data.
*/
private const val INITIAL_LOAD_COUNT = 30L
internal class LoadTimelineStrategy(
private val roomId: String,
private val timelineId: String,
@ -45,7 +48,7 @@ internal class LoadTimelineStrategy(
private val dependencies: Dependencies) {
sealed class Mode {
object Default : Mode()
object Live : Mode()
data class Permalink(val originEventId: String) : Mode()
fun originEventId(): String? {
@ -109,7 +112,7 @@ internal class LoadTimelineStrategy(
override fun onNewTimelineEvents(roomId: String, eventIds: List<String>) {
super.onNewTimelineEvents(roomId, eventIds)
if (mode == Mode.Default && roomId == this@LoadTimelineStrategy.roomId) {
if (mode == Mode.Live && roomId == this@LoadTimelineStrategy.roomId) {
dependencies.onNewTimelineEvents(eventIds)
}
}
@ -133,8 +136,8 @@ internal class LoadTimelineStrategy(
it.addChangeListener(chunkEntityListener)
timelineChunk = it.createTimelineChunk()
}
if (mode is Mode.Default) {
loadMore(10, Timeline.Direction.BACKWARDS)
if (mode is Mode.Live) {
loadMore(INITIAL_LOAD_COUNT, Timeline.Direction.BACKWARDS)
}
}