Rename isInit to isTimelineInitialized for clarity.

This commit is contained in:
Benoit Marty 2024-09-12 16:27:52 +02:00
parent ba4ef08756
commit 4cfda8e4aa
4 changed files with 18 additions and 14 deletions

View file

@ -86,7 +86,7 @@ class RustTimeline(
onNewSyncedEvent: () -> Unit, onNewSyncedEvent: () -> Unit,
) : Timeline { ) : Timeline {
private val initLatch = CompletableDeferred<Unit>() private val initLatch = CompletableDeferred<Unit>()
private val isInit = MutableStateFlow(false) private val isTimelineInitialized = MutableStateFlow(false)
private val _timelineItems: MutableStateFlow<List<MatrixTimelineItem>> = private val _timelineItems: MutableStateFlow<List<MatrixTimelineItem>> =
MutableStateFlow(emptyList()) MutableStateFlow(emptyList())
@ -110,7 +110,7 @@ class RustTimeline(
timelineCoroutineScope = coroutineScope, timelineCoroutineScope = coroutineScope,
timelineDiffProcessor = timelineDiffProcessor, timelineDiffProcessor = timelineDiffProcessor,
initLatch = initLatch, initLatch = initLatch,
isInit = isInit, isTimelineInitialized = isTimelineInitialized,
dispatcher = dispatcher, dispatcher = dispatcher,
onNewSyncedEvent = onNewSyncedEvent, onNewSyncedEvent = onNewSyncedEvent,
) )
@ -189,7 +189,7 @@ class RustTimeline(
} }
private fun canPaginate(direction: Timeline.PaginationDirection): Boolean { private fun canPaginate(direction: Timeline.PaginationDirection): Boolean {
if (!isInit.value) return false if (!isTimelineInitialized.value) return false
return when (direction) { return when (direction) {
Timeline.PaginationDirection.BACKWARDS -> backPaginationStatus.value.canPaginate Timeline.PaginationDirection.BACKWARDS -> backPaginationStatus.value.canPaginate
Timeline.PaginationDirection.FORWARDS -> forwardPaginationStatus.value.canPaginate Timeline.PaginationDirection.FORWARDS -> forwardPaginationStatus.value.canPaginate
@ -208,8 +208,12 @@ class RustTimeline(
backPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(), backPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(),
forwardPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(), forwardPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(),
matrixRoom.roomInfoFlow.map { it.creator }, matrixRoom.roomInfoFlow.map { it.creator },
isInit, isTimelineInitialized,
) { timelineItems, hasMoreToLoadBackward, hasMoreToLoadForward, roomCreator, isInit -> ) { timelineItems,
hasMoreToLoadBackward,
hasMoreToLoadForward,
roomCreator,
isTimelineInitialized ->
withContext(dispatcher) { withContext(dispatcher) {
timelineItems timelineItems
.let { items -> .let { items ->
@ -223,7 +227,7 @@ class RustTimeline(
.let { items -> .let { items ->
loadingIndicatorsPostProcessor.process( loadingIndicatorsPostProcessor.process(
items = items, items = items,
isInit = isInit, isTimelineInitialized = isTimelineInitialized,
hasMoreToLoadBackward = hasMoreToLoadBackward, hasMoreToLoadBackward = hasMoreToLoadBackward,
hasMoreToLoadForward = hasMoreToLoadForward hasMoreToLoadForward = hasMoreToLoadForward
) )
@ -232,7 +236,7 @@ class RustTimeline(
.let { items -> .let { items ->
lastForwardIndicatorsPostProcessor.process( lastForwardIndicatorsPostProcessor.process(
items = items, items = items,
isInit = isInit, isTimelineInitialized = isTimelineInitialized,
) )
} }
} }

View file

@ -38,7 +38,7 @@ internal class TimelineItemsSubscriber(
private val timeline: Timeline, private val timeline: Timeline,
private val timelineDiffProcessor: MatrixTimelineDiffProcessor, private val timelineDiffProcessor: MatrixTimelineDiffProcessor,
private val initLatch: CompletableDeferred<Unit>, private val initLatch: CompletableDeferred<Unit>,
private val isInit: MutableStateFlow<Boolean>, private val isTimelineInitialized: MutableStateFlow<Boolean>,
private val onNewSyncedEvent: () -> Unit, private val onNewSyncedEvent: () -> Unit,
) { ) {
private var subscriptionCount = 0 private var subscriptionCount = 0
@ -85,13 +85,13 @@ internal class TimelineItemsSubscriber(
ensureActive() ensureActive()
timelineDiffProcessor.postItems(it) timelineDiffProcessor.postItems(it)
} }
isInit.value = true isTimelineInitialized.value = true
initLatch.complete(Unit) initLatch.complete(Unit)
} }
private suspend fun postDiffs(diffs: List<TimelineDiff>) { private suspend fun postDiffs(diffs: List<TimelineDiff>) {
val diffsToProcess = diffs.toMutableList() val diffsToProcess = diffs.toMutableList()
if (!isInit.value) { if (!isTimelineInitialized.value) {
val resetDiff = diffsToProcess.firstOrNull { it.change() == TimelineChange.RESET } val resetDiff = diffsToProcess.firstOrNull { it.change() == TimelineChange.RESET }
if (resetDiff != null) { if (resetDiff != null) {
// Keep using the postItems logic so we can post the timelineItems asap. // Keep using the postItems logic so we can post the timelineItems asap.

View file

@ -22,9 +22,9 @@ class LastForwardIndicatorsPostProcessor(
fun process( fun process(
items: List<MatrixTimelineItem>, items: List<MatrixTimelineItem>,
isInit: Boolean, isTimelineInitialized: Boolean,
): List<MatrixTimelineItem> { ): List<MatrixTimelineItem> {
if (!isInit) return items if (!isTimelineInitialized) return items
// We don't need to add the last forward indicator if we are not in the FOCUSED_ON_EVENT mode // We don't need to add the last forward indicator if we are not in the FOCUSED_ON_EVENT mode
if (mode != Timeline.Mode.FOCUSED_ON_EVENT) { if (mode != Timeline.Mode.FOCUSED_ON_EVENT) {
return items return items

View file

@ -16,11 +16,11 @@ import io.element.android.services.toolbox.api.systemclock.SystemClock
class LoadingIndicatorsPostProcessor(private val systemClock: SystemClock) { class LoadingIndicatorsPostProcessor(private val systemClock: SystemClock) {
fun process( fun process(
items: List<MatrixTimelineItem>, items: List<MatrixTimelineItem>,
isInit: Boolean, isTimelineInitialized: Boolean,
hasMoreToLoadBackward: Boolean, hasMoreToLoadBackward: Boolean,
hasMoreToLoadForward: Boolean, hasMoreToLoadForward: Boolean,
): List<MatrixTimelineItem> { ): List<MatrixTimelineItem> {
if (!isInit) return items if (!isTimelineInitialized) return items
val shouldAddForwardLoadingIndicator = hasMoreToLoadForward && items.isNotEmpty() val shouldAddForwardLoadingIndicator = hasMoreToLoadForward && items.isNotEmpty()
val currentTimestamp = systemClock.epochMillis() val currentTimestamp = systemClock.epochMillis()
return buildList { return buildList {