Timeline : remove some code from main thread
This commit is contained in:
parent
bf3186353d
commit
9844a642c0
2 changed files with 33 additions and 29 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue