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:
commit
20ae35cf22
2 changed files with 33 additions and 29 deletions
|
|
@ -31,7 +31,7 @@ class MatrixTimelineItemMapper(
|
||||||
private val eventTimelineItemMapper: EventTimelineItemMapper = EventTimelineItemMapper(),
|
private val eventTimelineItemMapper: EventTimelineItemMapper = EventTimelineItemMapper(),
|
||||||
) {
|
) {
|
||||||
fun map(timelineItem: TimelineItem): MatrixTimelineItem = timelineItem.use {
|
fun map(timelineItem: TimelineItem): MatrixTimelineItem = timelineItem.use {
|
||||||
val uniqueId = timelineItem.uniqueId().toString()
|
val uniqueId = timelineItem.uniqueId()
|
||||||
val asEvent = it.asEvent()
|
val asEvent = it.asEvent()
|
||||||
if (asEvent != null) {
|
if (asEvent != null) {
|
||||||
val eventTimelineItem = eventTimelineItemMapper.map(asEvent)
|
val eventTimelineItem = eventTimelineItemMapper.map(asEvent)
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,7 @@ class RustTimeline(
|
||||||
|
|
||||||
// Use NonCancellable to avoid breaking the timeline when the coroutine is cancelled.
|
// Use NonCancellable to avoid breaking the timeline when the coroutine is cancelled.
|
||||||
override suspend fun paginate(direction: Timeline.PaginationDirection): Result<Boolean> = withContext(NonCancellable) {
|
override suspend fun paginate(direction: Timeline.PaginationDirection): Result<Boolean> = withContext(NonCancellable) {
|
||||||
|
withContext(dispatcher) {
|
||||||
initLatch.await()
|
initLatch.await()
|
||||||
runCatching {
|
runCatching {
|
||||||
if (!canPaginate(direction)) throw TimelineException.CannotPaginate
|
if (!canPaginate(direction)) throw TimelineException.CannotPaginate
|
||||||
|
|
@ -193,6 +194,7 @@ class RustTimeline(
|
||||||
updatePaginationStatus(direction) { it.copy(isPaginating = false, hasMoreToLoad = !hasReachedEnd) }
|
updatePaginationStatus(direction) { it.copy(isPaginating = false, hasMoreToLoad = !hasReachedEnd) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun canPaginate(direction: Timeline.PaginationDirection): Boolean {
|
private fun canPaginate(direction: Timeline.PaginationDirection): Boolean {
|
||||||
if (!isInit.get()) return false
|
if (!isInit.get()) return false
|
||||||
|
|
@ -214,6 +216,7 @@ class RustTimeline(
|
||||||
backPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(),
|
backPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(),
|
||||||
forwardPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(),
|
forwardPaginationStatus.map { it.hasMoreToLoad }.distinctUntilChanged(),
|
||||||
) { timelineItems, hasMoreToLoadBackward, hasMoreToLoadForward ->
|
) { timelineItems, hasMoreToLoadBackward, hasMoreToLoadForward ->
|
||||||
|
withContext(dispatcher) {
|
||||||
timelineItems
|
timelineItems
|
||||||
.let { items -> encryptedHistoryPostProcessor.process(items) }
|
.let { items -> encryptedHistoryPostProcessor.process(items) }
|
||||||
.let { items ->
|
.let { items ->
|
||||||
|
|
@ -227,6 +230,7 @@ class RustTimeline(
|
||||||
// Keep lastForwardIndicatorsPostProcessor last
|
// Keep lastForwardIndicatorsPostProcessor last
|
||||||
.let { items -> lastForwardIndicatorsPostProcessor.process(items) }
|
.let { items -> lastForwardIndicatorsPostProcessor.process(items) }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
inner.close()
|
inner.close()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue