Timeline: move TimelineEncryptedHistoryPostProcessor off the main thread
This commit is contained in:
parent
a4e2b7a114
commit
ea35e36aff
4 changed files with 22 additions and 11 deletions
|
|
@ -81,6 +81,7 @@ class RustMatrixTimeline(
|
|||
lastLoginTimestamp = lastLoginTimestamp,
|
||||
isRoomEncrypted = matrixRoom.isEncrypted,
|
||||
paginationStateFlow = _paginationState,
|
||||
dispatcher = dispatcher,
|
||||
)
|
||||
|
||||
private val timelineItemFactory = MatrixTimelineItemMapper(
|
||||
|
|
|
|||
|
|
@ -19,18 +19,23 @@ package io.element.android.libraries.matrix.impl.timeline.postprocessor
|
|||
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
|
||||
import io.element.android.libraries.matrix.api.timeline.MatrixTimelineItem
|
||||
import io.element.android.libraries.matrix.api.timeline.item.virtual.VirtualTimelineItem
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.getAndUpdate
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import java.util.Date
|
||||
|
||||
class TimelineEncryptedHistoryPostProcessor(
|
||||
private val dispatcher: CoroutineDispatcher,
|
||||
private val lastLoginTimestamp: Date?,
|
||||
private val isRoomEncrypted: Boolean,
|
||||
private val paginationStateFlow: MutableStateFlow<MatrixTimeline.PaginationState>,
|
||||
) {
|
||||
|
||||
fun process(items: List<MatrixTimelineItem>): List<MatrixTimelineItem> {
|
||||
if (!isRoomEncrypted || lastLoginTimestamp == null) return items
|
||||
suspend fun process(items: List<MatrixTimelineItem>): List<MatrixTimelineItem> = withContext(dispatcher) {
|
||||
Timber.d("Process on Thread=${Thread.currentThread()}")
|
||||
if (!isRoomEncrypted || lastLoginTimestamp == null) return@withContext items
|
||||
|
||||
val filteredItems = replaceWithEncryptionHistoryBannerIfNeeded(items)
|
||||
// Disable back pagination
|
||||
|
|
@ -43,7 +48,7 @@ class TimelineEncryptedHistoryPostProcessor(
|
|||
)
|
||||
}
|
||||
}
|
||||
return filteredItems
|
||||
filteredItems
|
||||
}
|
||||
|
||||
private fun replaceWithEncryptionHistoryBannerIfNeeded(list: List<MatrixTimelineItem>): List<MatrixTimelineItem> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue