mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-05 22:36:34 +00:00
Use an AtomicBoolean instead of a MutableStateFlow to atomically init the RustMatrixRoom. Should improve #951.
This commit is contained in:
+8
-6
@@ -65,6 +65,7 @@ import org.matrix.rustcomponents.sdk.genTransactionId
|
||||
import org.matrix.rustcomponents.sdk.messageEventContentFromMarkdown
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class RustMatrixRoom(
|
||||
@@ -88,7 +89,7 @@ class RustMatrixRoom(
|
||||
|
||||
private val roomCoroutineScope = sessionCoroutineScope.childScope(coroutineDispatchers.main, "RoomScope-$roomId")
|
||||
private val _membersStateFlow = MutableStateFlow<MatrixRoomMembersState>(MatrixRoomMembersState.Unknown)
|
||||
private val isInit = MutableStateFlow(false)
|
||||
private val isInit = AtomicBoolean(false)
|
||||
private val _syncUpdateFlow = MutableStateFlow(0L)
|
||||
private val _timeline by lazy {
|
||||
RustMatrixTimeline(
|
||||
@@ -107,7 +108,9 @@ class RustMatrixRoom(
|
||||
override val timeline: MatrixTimeline = _timeline
|
||||
|
||||
override fun open(): Result<Unit> {
|
||||
if (isInit.value) return Result.failure(IllegalStateException("Listener already registered"))
|
||||
return if (isInit.getAndSet(true)) {
|
||||
Result.failure(IllegalStateException("Listener already registered"))
|
||||
} else {
|
||||
val settings = RoomSubscription(
|
||||
requiredState = listOf(
|
||||
RequiredState(key = EventType.STATE_ROOM_CANONICAL_ALIAS, value = ""),
|
||||
@@ -135,13 +138,12 @@ class RustMatrixRoom(
|
||||
|
||||
fetchMembers()
|
||||
}
|
||||
isInit.value = true
|
||||
return Result.success(Unit)
|
||||
Result.success(Unit)
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
if (isInit.value) {
|
||||
isInit.value = false
|
||||
if (isInit.getAndSet(false)) {
|
||||
roomCoroutineScope.cancel()
|
||||
roomListItem.unsubscribe()
|
||||
innerRoom.destroy()
|
||||
|
||||
Reference in New Issue
Block a user