mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-25 15:08:12 +08:00
Handle PR review remarks
This commit is contained in:
parent
bcbc6c0f7c
commit
08cdac3e0d
@ -20,7 +20,14 @@ import com.airbnb.mvrx.Async
|
||||
import com.airbnb.mvrx.Fail
|
||||
import com.airbnb.mvrx.Success
|
||||
|
||||
fun <A> Result<A>.foldToAsync(): Async<A> = fold(
|
||||
/**
|
||||
* Note: this will be removed when upgrading to mvrx2
|
||||
*/
|
||||
suspend fun <A> runCatchingToAsync(block: suspend () -> A): Async<A> {
|
||||
return runCatching {
|
||||
block.invoke()
|
||||
}.fold(
|
||||
{ Success(it) },
|
||||
{ Fail(it) }
|
||||
)
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user