Timeline : Add isInit to avoid calling rust methods when the timeline is not ready.
This commit is contained in:
parent
7eddf1201a
commit
b6179b9760
1 changed files with 8 additions and 0 deletions
|
|
@ -42,6 +42,7 @@ import org.matrix.rustcomponents.sdk.SlidingSyncRoom
|
||||||
import org.matrix.rustcomponents.sdk.TimelineItem
|
import org.matrix.rustcomponents.sdk.TimelineItem
|
||||||
import org.matrix.rustcomponents.sdk.TimelineListener
|
import org.matrix.rustcomponents.sdk.TimelineListener
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
class RustMatrixTimeline(
|
class RustMatrixTimeline(
|
||||||
private val matrixRoom: MatrixRoom,
|
private val matrixRoom: MatrixRoom,
|
||||||
|
|
@ -51,6 +52,8 @@ class RustMatrixTimeline(
|
||||||
private val coroutineDispatchers: CoroutineDispatchers,
|
private val coroutineDispatchers: CoroutineDispatchers,
|
||||||
) : MatrixTimeline {
|
) : MatrixTimeline {
|
||||||
|
|
||||||
|
private val isInit = AtomicBoolean(false)
|
||||||
|
|
||||||
private val timelineItems: MutableStateFlow<List<MatrixTimelineItem>> =
|
private val timelineItems: MutableStateFlow<List<MatrixTimelineItem>> =
|
||||||
MutableStateFlow(emptyList())
|
MutableStateFlow(emptyList())
|
||||||
|
|
||||||
|
|
@ -95,6 +98,7 @@ class RustMatrixTimeline(
|
||||||
withContext(coroutineDispatchers.diffUpdateDispatcher) {
|
withContext(coroutineDispatchers.diffUpdateDispatcher) {
|
||||||
this@RustMatrixTimeline.timelineItems.value = matrixTimelineItems
|
this@RustMatrixTimeline.timelineItems.value = matrixTimelineItems
|
||||||
}
|
}
|
||||||
|
isInit.set(true)
|
||||||
}
|
}
|
||||||
.onFailure {
|
.onFailure {
|
||||||
Timber.e("Failed adding timeline listener on room with identifier: ${matrixRoom.roomId})")
|
Timber.e("Failed adding timeline listener on room with identifier: ${matrixRoom.roomId})")
|
||||||
|
|
@ -105,6 +109,7 @@ class RustMatrixTimeline(
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
Timber.v("Dispose timeline for room ${matrixRoom.roomId}")
|
Timber.v("Dispose timeline for room ${matrixRoom.roomId}")
|
||||||
listenerTokens.dispose()
|
listenerTokens.dispose()
|
||||||
|
isInit.set(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -125,6 +130,9 @@ class RustMatrixTimeline(
|
||||||
override suspend fun paginateBackwards(requestSize: Int, untilNumberOfItems: Int): Result<Unit> = withContext(coroutineDispatchers.io) {
|
override suspend fun paginateBackwards(requestSize: Int, untilNumberOfItems: Int): Result<Unit> = withContext(coroutineDispatchers.io) {
|
||||||
runCatching {
|
runCatching {
|
||||||
Timber.v("Start back paginating for room ${matrixRoom.roomId} ")
|
Timber.v("Start back paginating for room ${matrixRoom.roomId} ")
|
||||||
|
if (!isInit.get()) {
|
||||||
|
throw IllegalStateException("Timeline is not init yet")
|
||||||
|
}
|
||||||
val paginationOptions = PaginationOptions.UntilNumItems(
|
val paginationOptions = PaginationOptions.UntilNumItems(
|
||||||
eventLimit = requestSize.toUShort(),
|
eventLimit = requestSize.toUShort(),
|
||||||
items = untilNumberOfItems.toUShort()
|
items = untilNumberOfItems.toUShort()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue