Moving DM creation/opening into the member profile screen

This commit is contained in:
Maxime Naturel 2022-02-21 18:00:21 +01:00
parent 836bf4e11e
commit 46854b4b84
4 changed files with 26 additions and 2 deletions

View file

@ -29,4 +29,5 @@ sealed class RoomMemberProfileAction : VectorViewModelAction {
object ShareRoomMemberProfile : RoomMemberProfileAction()
data class SetPowerLevel(val previousValue: Int, val newValue: Int, val askForValidation: Boolean) : RoomMemberProfileAction()
data class SetUserColorOverride(val newColorSpec: String) : RoomMemberProfileAction()
data class OpenOrCreateDm(val userId: String) : RoomMemberProfileAction()
}

View file

@ -127,6 +127,7 @@ class RoomMemberProfileFragment @Inject constructor(
is RoomMemberProfileViewEvents.ShareRoomMemberProfile -> handleShareRoomMemberProfile(it.permalink)
is RoomMemberProfileViewEvents.ShowPowerLevelValidation -> handleShowPowerLevelAdminWarning(it)
is RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning -> handleShowPowerLevelDemoteWarning(it)
is RoomMemberProfileViewEvents.OpenRoom -> handleOpenRoom(it)
is RoomMemberProfileViewEvents.OnKickActionSuccess -> Unit
is RoomMemberProfileViewEvents.OnSetPowerLevelSuccess -> Unit
is RoomMemberProfileViewEvents.OnBanActionSuccess -> Unit
@ -142,6 +143,10 @@ class RoomMemberProfileFragment @Inject constructor(
headerViews.memberProfileIdView.copyOnLongClick()
}
private fun handleOpenRoom(event: RoomMemberProfileViewEvents.OpenRoom) {
navigator.openRoom(requireContext(), event.roomId, null)
}
private fun handleShowPowerLevelDemoteWarning(event: RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning) {
EditPowerLevelDialogs.showDemoteWarning(requireActivity()) {
viewModel.handle(RoomMemberProfileAction.SetPowerLevel(event.currentValue, event.newValue, false))
@ -297,8 +302,7 @@ class RoomMemberProfileFragment @Inject constructor(
}
override fun onOpenDmClicked() {
roomDetailPendingActionStore.data = RoomDetailPendingAction.OpenOrCreateDm(fragmentArgs.userId)
vectorBaseActivity.finish()
viewModel.handle(RoomMemberProfileAction.OpenOrCreateDm(fragmentArgs.userId))
}
override fun onJumpToReadReceiptClicked() {

View file

@ -39,4 +39,5 @@ sealed class RoomMemberProfileViewEvents : VectorViewEvents {
) : RoomMemberProfileViewEvents()
data class ShareRoomMemberProfile(val permalink: String) : RoomMemberProfileViewEvents()
data class OpenRoom(val roomId: String) : RoomMemberProfileViewEvents()
}

View file

@ -32,6 +32,7 @@ import im.vector.app.core.extensions.exhaustive
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.createdirect.DirectRoomHelper
import im.vector.app.features.displayname.getBestName
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
@ -66,6 +67,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
@Assisted private val initialState: RoomMemberProfileViewState,
private val stringProvider: StringProvider,
private val matrixItemColorProvider: MatrixItemColorProvider,
private val directRoomHelper: DirectRoomHelper,
private val session: Session
) : VectorViewModel<RoomMemberProfileViewState, RoomMemberProfileAction, RoomMemberProfileViewEvents>(initialState) {
@ -167,9 +169,25 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
is RoomMemberProfileAction.KickUser -> handleKickAction(action)
RoomMemberProfileAction.InviteUser -> handleInviteAction()
is RoomMemberProfileAction.SetUserColorOverride -> handleSetUserColorOverride(action)
is RoomMemberProfileAction.OpenOrCreateDm -> handleOpenOrCreateDm(action)
}.exhaustive
}
private fun handleOpenOrCreateDm(action: RoomMemberProfileAction.OpenOrCreateDm) {
viewModelScope.launch {
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
val roomId = try {
directRoomHelper.ensureDMExists(action.userId)
} catch (failure: Throwable) {
_viewEvents.post(RoomMemberProfileViewEvents.Failure(failure))
return@launch
}
if (roomId != initialState.roomId) {
_viewEvents.post(RoomMemberProfileViewEvents.OpenRoom(roomId = roomId))
}
}
}
private fun handleSetUserColorOverride(action: RoomMemberProfileAction.SetUserColorOverride) {
val newOverrideColorSpecs = session.accountDataService()
.getUserAccountDataEvent(UserAccountDataTypes.TYPE_OVERRIDE_COLORS)