Fix crash when leaving room using LeaveRoomPresenter (#2498)

This happened because `roomInfoFlow` was shared eagerly and the `initial` part was called after the `Room` Rust object was destroyed.

I think there isn't a need for room info to be shared, it was a mistake I forgot to rollback.
This commit is contained in:
Jorge Martin Espinosa 2024-03-06 17:39:44 +01:00 committed by GitHub
parent d8f9408cdb
commit 2f4e266094
3 changed files with 3 additions and 9 deletions

View file

@ -37,7 +37,6 @@ import io.element.android.libraries.matrix.api.widget.MatrixWidgetSettings
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toPersistentList import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
@ -63,7 +62,7 @@ interface MatrixRoom : Closeable {
/** Whether the room is a direct message. */ /** Whether the room is a direct message. */
val isDm: Boolean get() = isDirect && isOneToOne val isDm: Boolean get() = isDirect && isOneToOne
val roomInfoFlow: SharedFlow<MatrixRoomInfo> val roomInfoFlow: Flow<MatrixRoomInfo>
val roomTypingMembersFlow: Flow<List<UserId>> val roomTypingMembersFlow: Flow<List<UserId>>
/** /**

View file

@ -66,13 +66,10 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.matrix.rustcomponents.sdk.EventTimelineItem import org.matrix.rustcomponents.sdk.EventTimelineItem
@ -111,7 +108,7 @@ class RustMatrixRoom(
) : MatrixRoom { ) : MatrixRoom {
override val roomId = RoomId(innerRoom.id()) override val roomId = RoomId(innerRoom.id())
override val roomInfoFlow: SharedFlow<MatrixRoomInfo> = mxCallbackFlow { override val roomInfoFlow: Flow<MatrixRoomInfo> = mxCallbackFlow {
launch { launch {
val initial = innerRoom.roomInfo().use(matrixRoomInfoMapper::map) val initial = innerRoom.roomInfo().use(matrixRoomInfoMapper::map)
channel.trySend(initial) channel.trySend(initial)
@ -122,7 +119,6 @@ class RustMatrixRoom(
} }
}) })
} }
.shareIn(sessionCoroutineScope, SharingStarted.Eagerly, replay = 1)
override val roomTypingMembersFlow: Flow<List<UserId>> = mxCallbackFlow { override val roomTypingMembersFlow: Flow<List<UserId>> = mxCallbackFlow {
launch { launch {

View file

@ -62,7 +62,6 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import java.io.File import java.io.File
@ -180,7 +179,7 @@ class FakeMatrixRoom(
private var leaveRoomError: Throwable? = null private var leaveRoomError: Throwable? = null
private val _roomInfoFlow: MutableSharedFlow<MatrixRoomInfo> = MutableSharedFlow(replay = 1) private val _roomInfoFlow: MutableSharedFlow<MatrixRoomInfo> = MutableSharedFlow(replay = 1)
override val roomInfoFlow: SharedFlow<MatrixRoomInfo> = _roomInfoFlow override val roomInfoFlow: Flow<MatrixRoomInfo> = _roomInfoFlow
private val _roomTypingMembersFlow: MutableSharedFlow<List<UserId>> = MutableSharedFlow(replay = 1) private val _roomTypingMembersFlow: MutableSharedFlow<List<UserId>> = MutableSharedFlow(replay = 1)
override val roomTypingMembersFlow: Flow<List<UserId>> = _roomTypingMembersFlow override val roomTypingMembersFlow: Flow<List<UserId>> = _roomTypingMembersFlow