From 7b07adc5ab33ec164d940bf379bb75dae698d731 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 25 Apr 2024 15:01:18 +0200 Subject: [PATCH] Timeline : do not cancel pagination to avoid stuck timeline. --- .../libraries/matrix/impl/timeline/RustTimeline.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt index 43c53dcf0d..1e572d925d 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt @@ -54,6 +54,7 @@ import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.Flow @@ -173,9 +174,10 @@ class RustTimeline( } } - override suspend fun paginate(direction: Timeline.PaginationDirection): Result { + // Use NonCancellable to avoid breaking the timeline when the coroutine is cancelled. + override suspend fun paginate(direction: Timeline.PaginationDirection): Result = withContext(NonCancellable) { initLatch.await() - return runCatching { + runCatching { if (!canPaginate(direction)) throw TimelineException.CannotPaginate updatePaginationStatus(direction) { it.copy(isPaginating = true) } when (direction) { @@ -184,9 +186,6 @@ class RustTimeline( } }.onFailure { error -> updatePaginationStatus(direction) { it.copy(isPaginating = false) } - if (error is CancellationException) { - throw error - } if (error is TimelineException.CannotPaginate) { Timber.d("Can't paginate $direction on room ${matrixRoom.roomId} with paginationStatus: ${backPaginationStatus.value}") } else {