From b9b2072b28e198e30d76aa5b7a269d3bc4a43ad7 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 17 Apr 2024 23:19:38 +0200 Subject: [PATCH] Remove useless usage of coroutine scope. --- .../joinroom/impl/JoinRoomPresenter.kt | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/features/joinroom/impl/src/main/kotlin/io/element/android/features/joinroom/impl/JoinRoomPresenter.kt b/features/joinroom/impl/src/main/kotlin/io/element/android/features/joinroom/impl/JoinRoomPresenter.kt index f7feb43926..93399b0446 100644 --- a/features/joinroom/impl/src/main/kotlin/io/element/android/features/joinroom/impl/JoinRoomPresenter.kt +++ b/features/joinroom/impl/src/main/kotlin/io/element/android/features/joinroom/impl/JoinRoomPresenter.kt @@ -23,7 +23,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.produceState import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import dagger.assisted.Assisted import dagger.assisted.AssistedInject @@ -39,7 +38,6 @@ import io.element.android.libraries.matrix.api.core.toRoomIdOrAlias import io.element.android.libraries.matrix.api.room.CurrentUserMembership import io.element.android.libraries.matrix.api.room.MatrixRoomInfo import io.element.android.libraries.matrix.api.room.preview.RoomPreview -import kotlinx.coroutines.launch import java.util.Optional class JoinRoomPresenter @AssistedInject constructor( @@ -59,7 +57,6 @@ class JoinRoomPresenter @AssistedInject constructor( @Composable override fun present(): JoinRoomState { - val coroutineScope = rememberCoroutineScope() var retryCount by remember { mutableIntStateOf(0) } val roomInfo by matrixClient.getRoomInfoFlow(roomId).collectAsState(initial = Optional.empty()) val contentState by produceState( @@ -67,28 +64,26 @@ class JoinRoomPresenter @AssistedInject constructor( key1 = roomInfo, key2 = retryCount, ) { - value = when { + when { roomInfo.isPresent -> { - roomInfo.get().toContentState() + value = roomInfo.get().toContentState() } roomDescription.isPresent -> { - roomDescription.get().toContentState() + value = roomDescription.get().toContentState() } else -> { - coroutineScope.launch { - val result = matrixClient.getRoomPreview(roomId.toRoomIdOrAlias()) - value = result.fold( - onSuccess = { it.toContentState() }, - onFailure = { throwable -> - if (throwable.message?.contains("403") == true) { - ContentState.UnknownRoom(roomIdOrAlias) - } else { - ContentState.Failure(roomIdOrAlias, throwable) - } + value = ContentState.Loading(roomIdOrAlias) + val result = matrixClient.getRoomPreview(roomId.toRoomIdOrAlias()) + value = result.fold( + onSuccess = { it.toContentState() }, + onFailure = { throwable -> + if (throwable.message?.contains("403") == true) { + ContentState.UnknownRoom(roomIdOrAlias) + } else { + ContentState.Failure(roomIdOrAlias, throwable) } - ) - } - ContentState.Loading(roomIdOrAlias) + } + ) } } }