Handle PR review remarks

This commit is contained in:
Benoit Marty 2021-04-26 11:05:18 +02:00
parent bcbc6c0f7c
commit 08cdac3e0d
4 changed files with 20 additions and 13 deletions

View File

@ -20,7 +20,14 @@ import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Success import com.airbnb.mvrx.Success
fun <A> Result<A>.foldToAsync(): Async<A> = fold( /**
{ Success(it) }, * Note: this will be removed when upgrading to mvrx2
{ Fail(it) } */
) suspend fun <A> runCatchingToAsync(block: suspend () -> A): Async<A> {
return runCatching {
block.invoke()
}.fold(
{ Success(it) },
{ Fail(it) }
)
}

View File

@ -27,7 +27,7 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.mvrx.foldToAsync import im.vector.app.core.mvrx.runCatchingToAsync
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.raw.wellknown.getElementWellknown import im.vector.app.features.raw.wellknown.getElementWellknown
import im.vector.app.features.raw.wellknown.isE2EByDefault import im.vector.app.features.raw.wellknown.isE2EByDefault
@ -102,9 +102,9 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
enableEncryptionIfInvitedUsersSupportIt = adminE2EByDefault enableEncryptionIfInvitedUsersSupportIt = adminE2EByDefault
} }
val result = runCatching { val result = runCatchingToAsync {
session.createRoom(roomParams) session.createRoom(roomParams)
}.foldToAsync() }
setState { setState {
copy( copy(

View File

@ -35,7 +35,7 @@ import dagger.assisted.AssistedInject
import im.vector.app.BuildConfig import im.vector.app.BuildConfig
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.mvrx.foldToAsync import im.vector.app.core.mvrx.runCatchingToAsync
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.features.call.dialpad.DialPadLookup import im.vector.app.features.call.dialpad.DialPadLookup
@ -651,10 +651,10 @@ class RoomDetailViewModel @AssistedInject constructor(
?.let { listOf(it) } ?.let { listOf(it) }
.orEmpty() .orEmpty()
viewModelScope.launch { viewModelScope.launch {
val result = runCatching { val result = runCatchingToAsync {
session.joinRoom(roomId, viaServers = viaServers) session.joinRoom(roomId, viaServers = viaServers)
roomId roomId
}.foldToAsync() }
setState { setState {
copy(tombstoneEventHandling = result) copy(tombstoneEventHandling = result)
} }

View File

@ -29,7 +29,7 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.mvrx.foldToAsync import im.vector.app.core.mvrx.runCatchingToAsync
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.features.powerlevel.PowerLevelsObservableFactory import im.vector.app.features.powerlevel.PowerLevelsObservableFactory
@ -267,7 +267,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
} }
private suspend fun fetchProfileInfo() { private suspend fun fetchProfileInfo() {
val result = runCatching { val result = runCatchingToAsync {
session.getProfile(initialState.userId) session.getProfile(initialState.userId)
.let { .let {
MatrixItem.UserItem( MatrixItem.UserItem(
@ -276,7 +276,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
avatarUrl = it[ProfileService.AVATAR_URL_KEY] as? String avatarUrl = it[ProfileService.AVATAR_URL_KEY] as? String
) )
} }
}.foldToAsync() }
setState { setState {
copy(userMatrixItem = result) copy(userMatrixItem = result)