Merge pull request #2841 from element-hq/feature/fga/timeline_remove_from_main_thread

Timeline : remove some code from main thread
This commit is contained in:
ganfra 2024-05-14 16:12:37 +02:00 committed by GitHub
commit 20ae35cf22
2 changed files with 33 additions and 29 deletions

View file

@ -31,7 +31,7 @@ class MatrixTimelineItemMapper(
private val eventTimelineItemMapper: EventTimelineItemMapper = EventTimelineItemMapper(),
) {
fun map(timelineItem: TimelineItem): MatrixTimelineItem = timelineItem.use {
val uniqueId = timelineItem.uniqueId().toString()
val uniqueId = timelineItem.uniqueId()
val asEvent = it.asEvent()
if (asEvent != null) {
val eventTimelineItem = eventTimelineItemMapper.map(asEvent)

View file

@ -174,6 +174,7 @@ class RustTimeline(
// Use NonCancellable to avoid breaking the timeline when the coroutine is cancelled.
override suspend fun paginate(direction: Timeline.PaginationDirection): Result<Boolean> = withContext(NonCancellable) {
withContext(dispatcher) {
initLatch.await()
runCatching {
if (!canPaginate(direction)) throw TimelineException.CannotPaginate
@ -193,6 +194,7 @@ class RustTimeline(
updatePaginationStatus(direction) { it.copy(isPaginating = false, hasMoreToLoad = !hasReachedEnd) }
}
}
}
private fun canPaginate(direction: Timeline.PaginationDirection): Boolean {
if (!isInit.get()) return false
@ -214,6 +216,7 @@ class RustTimeline(
backPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(),
forwardPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(),
) { timelineItems, hasMoreToLoadBackward, hasMoreToLoadForward ->
withContext(dispatcher) {
timelineItems
.let { items -> encryptedHistoryPostProcessor.process(items) }
.let { items ->
@ -227,6 +230,7 @@ class RustTimeline(
// Keep lastForwardIndicatorsPostProcessor last
.let { items -> lastForwardIndicatorsPostProcessor.process(items) }
}
}
override fun close() {
inner.close()