mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-28 15:38:14 +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.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) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -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(
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user