From bf5ad2cf18717762ca0de8a30f181254ab2108bd Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 8 Jun 2020 17:36:30 +0200 Subject: [PATCH] Power level: warn when demoting yourself --- .../RoomMemberProfileFragment.kt | 27 ++++++++++++------- .../RoomMemberProfileViewEvents.kt | 1 + .../RoomMemberProfileViewModel.kt | 2 ++ .../powerlevel/EditPowerLevelDialogs.kt | 11 ++++++++ vector/src/main/res/values/strings.xml | 4 +++ 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt index e4034b389a..1c9ff24b80 100644 --- a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt @@ -97,20 +97,27 @@ class RoomMemberProfileFragment @Inject constructor( matrixProfileAppBarLayout.addOnOffsetChangedListener(appBarStateChangeListener) viewModel.observeViewEvents { when (it) { - is RoomMemberProfileViewEvents.Loading -> showLoading(it.message) - is RoomMemberProfileViewEvents.Failure -> showFailure(it.throwable) - is RoomMemberProfileViewEvents.StartVerification -> handleStartVerification(it) - is RoomMemberProfileViewEvents.ShareRoomMemberProfile -> handleShareRoomMemberProfile(it.permalink) - is RoomMemberProfileViewEvents.ShowPowerLevelValidation -> handleShowPowerLevelAdminWarning(it) - is RoomMemberProfileViewEvents.OnKickActionSuccess -> Unit - is RoomMemberProfileViewEvents.OnSetPowerLevelSuccess -> Unit - is RoomMemberProfileViewEvents.OnBanActionSuccess -> Unit - is RoomMemberProfileViewEvents.OnIgnoreActionSuccess -> Unit - is RoomMemberProfileViewEvents.OnInviteActionSuccess -> Unit + is RoomMemberProfileViewEvents.Loading -> showLoading(it.message) + is RoomMemberProfileViewEvents.Failure -> showFailure(it.throwable) + is RoomMemberProfileViewEvents.StartVerification -> handleStartVerification(it) + is RoomMemberProfileViewEvents.ShareRoomMemberProfile -> handleShareRoomMemberProfile(it.permalink) + is RoomMemberProfileViewEvents.ShowPowerLevelValidation -> handleShowPowerLevelAdminWarning(it) + is RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning -> handleShowPowerLevelDemoteWarning(it) + is RoomMemberProfileViewEvents.OnKickActionSuccess -> Unit + is RoomMemberProfileViewEvents.OnSetPowerLevelSuccess -> Unit + is RoomMemberProfileViewEvents.OnBanActionSuccess -> Unit + is RoomMemberProfileViewEvents.OnIgnoreActionSuccess -> Unit + is RoomMemberProfileViewEvents.OnInviteActionSuccess -> Unit }.exhaustive } } + private fun handleShowPowerLevelDemoteWarning(event: RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning) { + EditPowerLevelDialogs.showDemoteWarning(requireActivity()) { + viewModel.handle(RoomMemberProfileAction.SetPowerLevel(event.currentValue, event.newValue, false)) + } + } + private fun handleShowPowerLevelAdminWarning(event: RoomMemberProfileViewEvents.ShowPowerLevelValidation) { EditPowerLevelDialogs.showValidation(requireActivity()) { viewModel.handle(RoomMemberProfileAction.SetPowerLevel(event.currentValue, event.newValue, false)) diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewEvents.kt index 9aae5f7979..69c73007e0 100644 --- a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewEvents.kt +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewEvents.kt @@ -31,6 +31,7 @@ sealed class RoomMemberProfileViewEvents : VectorViewEvents { object OnKickActionSuccess : RoomMemberProfileViewEvents() object OnBanActionSuccess : RoomMemberProfileViewEvents() data class ShowPowerLevelValidation(val currentValue: Int, val newValue: Int) : RoomMemberProfileViewEvents() + data class ShowPowerLevelDemoteWarning(val currentValue: Int, val newValue: Int) : RoomMemberProfileViewEvents() data class StartVerification( val userId: String, diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewModel.kt index 9ce9e2088f..3573e79352 100644 --- a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileViewModel.kt @@ -158,6 +158,8 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v val myPowerLevel = PowerLevelsHelper(currentPowerLevelsContent).getUserPowerLevelValue(session.myUserId) if (action.askForValidation && action.newValue >= myPowerLevel) { _viewEvents.post(RoomMemberProfileViewEvents.ShowPowerLevelValidation(action.previousValue, action.newValue)) + } else if (state.isMine) { + _viewEvents.post(RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning(action.previousValue, action.newValue)) } else { currentPowerLevelsContent.users[state.userId] = action.newValue viewModelScope.launch { diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/powerlevel/EditPowerLevelDialogs.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/powerlevel/EditPowerLevelDialogs.kt index 636dfffb38..19e116a6de 100644 --- a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/powerlevel/EditPowerLevelDialogs.kt +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/powerlevel/EditPowerLevelDialogs.kt @@ -82,4 +82,15 @@ object EditPowerLevelDialogs { .setNegativeButton(R.string.no, null) .show() } + + fun showDemoteWarning(activity: Activity, onValidate: () -> Unit) { + AlertDialog.Builder(activity) + .setTitle(R.string.room_participants_power_level_demote_warning_title) + .setMessage(R.string.room_participants_power_level_demote_warning_prompt) + .setPositiveButton(R.string.room_participants_power_level_demote) { _, _ -> + onValidate() + } + .setNegativeButton(R.string.cancel, null) + .show() + } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 3a061a5550..932cb7c6bb 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -479,6 +479,10 @@ Show Session List You will not be able to undo this change as you are promoting the user to have the same power level as yourself.\nAre you sure? + Demote yourself? + "You will not be able to undo this change as you are demoting yourself, if you are the last privileged user in the room it will be impossible to regain privileges." + Demote + Ignore user Ignoring this user will remove their messages from rooms you share.\n\nYou can reverse this action at any time in the general settings.