Remove useless usage of coroutine scope.
This commit is contained in:
parent
98c285ece8
commit
f658969321
1 changed files with 14 additions and 19 deletions
|
|
@ -23,7 +23,6 @@ import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.produceState
|
import androidx.compose.runtime.produceState
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedInject
|
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.CurrentUserMembership
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoomInfo
|
import io.element.android.libraries.matrix.api.room.MatrixRoomInfo
|
||||||
import io.element.android.libraries.matrix.api.room.preview.RoomPreview
|
import io.element.android.libraries.matrix.api.room.preview.RoomPreview
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import java.util.Optional
|
import java.util.Optional
|
||||||
|
|
||||||
class JoinRoomPresenter @AssistedInject constructor(
|
class JoinRoomPresenter @AssistedInject constructor(
|
||||||
|
|
@ -59,7 +57,6 @@ class JoinRoomPresenter @AssistedInject constructor(
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun present(): JoinRoomState {
|
override fun present(): JoinRoomState {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
|
||||||
var retryCount by remember { mutableIntStateOf(0) }
|
var retryCount by remember { mutableIntStateOf(0) }
|
||||||
val roomInfo by matrixClient.getRoomInfoFlow(roomId).collectAsState(initial = Optional.empty())
|
val roomInfo by matrixClient.getRoomInfoFlow(roomId).collectAsState(initial = Optional.empty())
|
||||||
val contentState by produceState<ContentState>(
|
val contentState by produceState<ContentState>(
|
||||||
|
|
@ -67,28 +64,26 @@ class JoinRoomPresenter @AssistedInject constructor(
|
||||||
key1 = roomInfo,
|
key1 = roomInfo,
|
||||||
key2 = retryCount,
|
key2 = retryCount,
|
||||||
) {
|
) {
|
||||||
value = when {
|
when {
|
||||||
roomInfo.isPresent -> {
|
roomInfo.isPresent -> {
|
||||||
roomInfo.get().toContentState()
|
value = roomInfo.get().toContentState()
|
||||||
}
|
}
|
||||||
roomDescription.isPresent -> {
|
roomDescription.isPresent -> {
|
||||||
roomDescription.get().toContentState()
|
value = roomDescription.get().toContentState()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
coroutineScope.launch {
|
value = ContentState.Loading(roomIdOrAlias)
|
||||||
val result = matrixClient.getRoomPreview(roomId.toRoomIdOrAlias())
|
val result = matrixClient.getRoomPreview(roomId.toRoomIdOrAlias())
|
||||||
value = result.fold(
|
value = result.fold(
|
||||||
onSuccess = { it.toContentState() },
|
onSuccess = { it.toContentState() },
|
||||||
onFailure = { throwable ->
|
onFailure = { throwable ->
|
||||||
if (throwable.message?.contains("403") == true) {
|
if (throwable.message?.contains("403") == true) {
|
||||||
ContentState.UnknownRoom(roomIdOrAlias)
|
ContentState.UnknownRoom(roomIdOrAlias)
|
||||||
} else {
|
} else {
|
||||||
ContentState.Failure(roomIdOrAlias, throwable)
|
ContentState.Failure(roomIdOrAlias, throwable)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
}
|
)
|
||||||
ContentState.Loading(roomIdOrAlias)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue