diff --git a/vector/src/main/java/im/vector/app/core/mvrx/ResultExtension.kt b/vector/src/main/java/im/vector/app/core/mvrx/ResultExtension.kt index 1dbf658deb..dfd04ea6f6 100644 --- a/vector/src/main/java/im/vector/app/core/mvrx/ResultExtension.kt +++ b/vector/src/main/java/im/vector/app/core/mvrx/ResultExtension.kt @@ -20,7 +20,14 @@ import com.airbnb.mvrx.Async import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Success -fun Result.foldToAsync(): Async = fold( - { Success(it) }, - { Fail(it) } -) +/** + * Note: this will be removed when upgrading to mvrx2 + */ +suspend fun runCatchingToAsync(block: suspend () -> A): Async { + return runCatching { + block.invoke() + }.fold( + { Success(it) }, + { Fail(it) } + ) +} diff --git a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt index 9d6f6da54b..2f0b6e5ec9 100644 --- a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomViewModel.kt @@ -27,7 +27,7 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedInject import dagger.assisted.AssistedFactory 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.features.raw.wellknown.getElementWellknown import im.vector.app.features.raw.wellknown.isE2EByDefault @@ -102,9 +102,9 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted enableEncryptionIfInvitedUsersSupportIt = adminE2EByDefault } - val result = runCatching { + val result = runCatchingToAsync { session.createRoom(roomParams) - }.foldToAsync() + } setState { copy( diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index 725cce70ab..006a2c9b5f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -35,7 +35,7 @@ import dagger.assisted.AssistedInject import im.vector.app.BuildConfig import im.vector.app.R 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.resources.StringProvider import im.vector.app.features.call.dialpad.DialPadLookup @@ -651,10 +651,10 @@ class RoomDetailViewModel @AssistedInject constructor( ?.let { listOf(it) } .orEmpty() viewModelScope.launch { - val result = runCatching { + val result = runCatchingToAsync { session.joinRoom(roomId, viaServers = viaServers) roomId - }.foldToAsync() + } setState { copy(tombstoneEventHandling = result) } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt index 0fa681a799..7b05c6c7f5 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt @@ -29,7 +29,7 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedInject import dagger.assisted.AssistedFactory 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.resources.StringProvider import im.vector.app.features.powerlevel.PowerLevelsObservableFactory @@ -267,7 +267,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v } private suspend fun fetchProfileInfo() { - val result = runCatching { + val result = runCatchingToAsync { session.getProfile(initialState.userId) .let { MatrixItem.UserItem( @@ -276,7 +276,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v avatarUrl = it[ProfileService.AVATAR_URL_KEY] as? String ) } - }.foldToAsync() + } setState { copy(userMatrixItem = result)