Add a View to show the beginning of the timeline (parity with iOS)

This commit is contained in:
Benoit Marty 2023-11-14 17:06:19 +01:00
parent 5209627f67
commit 2cb0060f96
33 changed files with 156 additions and 28 deletions

View file

@ -72,7 +72,11 @@ class RustMatrixTimeline(
MutableStateFlow(emptyList())
private val _paginationState = MutableStateFlow(
MatrixTimeline.PaginationState(hasMoreToLoadBackwards = true, isBackPaginating = false)
MatrixTimeline.PaginationState(
hasMoreToLoadBackwards = true,
isBackPaginating = false,
beginningOfRoomReached = false,
)
)
private val encryptedHistoryPostProcessor = TimelineEncryptedHistoryPostProcessor(
@ -155,6 +159,7 @@ class RustMatrixTimeline(
return@getAndUpdate currentPaginationState.copy(
isBackPaginating = false,
hasMoreToLoadBackwards = false,
beginningOfRoomReached = false,
)
}
when (status) {
@ -173,7 +178,8 @@ class RustMatrixTimeline(
BackPaginationStatus.TIMELINE_START_REACHED -> {
currentPaginationState.copy(
isBackPaginating = false,
hasMoreToLoadBackwards = false
hasMoreToLoadBackwards = false,
beginningOfRoomReached = true,
)
}
}

View file

@ -45,7 +45,8 @@ class TimelineEncryptedHistoryPostProcessor(
paginationStateFlow.getAndUpdate {
it.copy(
isBackPaginating = false,
hasMoreToLoadBackwards = false
hasMoreToLoadBackwards = false,
beginningOfRoomReached = false,
)
}
}

View file

@ -98,7 +98,13 @@ class TimelineEncryptedHistoryPostProcessorTest {
@Test
fun `given a list with several with lower or equal timestamps than lastLoginTimestamp, they're replaced and the user can't back paginate`() = runTest {
val paginationStateFlow = MutableStateFlow(MatrixTimeline.PaginationState(hasMoreToLoadBackwards = true, isBackPaginating = false))
val paginationStateFlow = MutableStateFlow(
MatrixTimeline.PaginationState(
hasMoreToLoadBackwards = true,
isBackPaginating = false,
beginningOfRoomReached = false,
)
)
val processor = createPostProcessor(paginationStateFlow = paginationStateFlow)
val items = listOf(
MatrixTimelineItem.Event(0L, anEventTimelineItem(timestamp = defaultLastLoginTimestamp.time - 1)),
@ -111,7 +117,13 @@ class TimelineEncryptedHistoryPostProcessorTest {
MatrixTimelineItem.Event(0L, anEventTimelineItem(timestamp = defaultLastLoginTimestamp.time + 1))
)
)
assertThat(paginationStateFlow.value).isEqualTo(MatrixTimeline.PaginationState(hasMoreToLoadBackwards = false, isBackPaginating = false))
assertThat(paginationStateFlow.value).isEqualTo(
MatrixTimeline.PaginationState(
hasMoreToLoadBackwards = false,
isBackPaginating = false,
beginningOfRoomReached = false,
)
)
}
private fun TestScope.createPostProcessor(
@ -119,7 +131,13 @@ class TimelineEncryptedHistoryPostProcessorTest {
isRoomEncrypted: Boolean = true,
isKeyBackupEnabled: Boolean = false,
paginationStateFlow: MutableStateFlow<MatrixTimeline.PaginationState> =
MutableStateFlow(MatrixTimeline.PaginationState(hasMoreToLoadBackwards = true, isBackPaginating = false))
MutableStateFlow(
MatrixTimeline.PaginationState(
hasMoreToLoadBackwards = true,
isBackPaginating = false,
beginningOfRoomReached = false,
)
)
) = TimelineEncryptedHistoryPostProcessor(
lastLoginTimestamp = lastLoginTimestamp,
isRoomEncrypted = isRoomEncrypted,