Power level: warn when demoting yourself

This commit is contained in:
ganfra 2020-06-08 17:36:30 +02:00
parent a8ae4ddde8
commit bf5ad2cf18
5 changed files with 35 additions and 10 deletions

View File

@ -97,20 +97,27 @@ class RoomMemberProfileFragment @Inject constructor(
matrixProfileAppBarLayout.addOnOffsetChangedListener(appBarStateChangeListener) matrixProfileAppBarLayout.addOnOffsetChangedListener(appBarStateChangeListener)
viewModel.observeViewEvents { viewModel.observeViewEvents {
when (it) { when (it) {
is RoomMemberProfileViewEvents.Loading -> showLoading(it.message) is RoomMemberProfileViewEvents.Loading -> showLoading(it.message)
is RoomMemberProfileViewEvents.Failure -> showFailure(it.throwable) is RoomMemberProfileViewEvents.Failure -> showFailure(it.throwable)
is RoomMemberProfileViewEvents.StartVerification -> handleStartVerification(it) is RoomMemberProfileViewEvents.StartVerification -> handleStartVerification(it)
is RoomMemberProfileViewEvents.ShareRoomMemberProfile -> handleShareRoomMemberProfile(it.permalink) is RoomMemberProfileViewEvents.ShareRoomMemberProfile -> handleShareRoomMemberProfile(it.permalink)
is RoomMemberProfileViewEvents.ShowPowerLevelValidation -> handleShowPowerLevelAdminWarning(it) is RoomMemberProfileViewEvents.ShowPowerLevelValidation -> handleShowPowerLevelAdminWarning(it)
is RoomMemberProfileViewEvents.OnKickActionSuccess -> Unit is RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning -> handleShowPowerLevelDemoteWarning(it)
is RoomMemberProfileViewEvents.OnSetPowerLevelSuccess -> Unit is RoomMemberProfileViewEvents.OnKickActionSuccess -> Unit
is RoomMemberProfileViewEvents.OnBanActionSuccess -> Unit is RoomMemberProfileViewEvents.OnSetPowerLevelSuccess -> Unit
is RoomMemberProfileViewEvents.OnIgnoreActionSuccess -> Unit is RoomMemberProfileViewEvents.OnBanActionSuccess -> Unit
is RoomMemberProfileViewEvents.OnInviteActionSuccess -> Unit is RoomMemberProfileViewEvents.OnIgnoreActionSuccess -> Unit
is RoomMemberProfileViewEvents.OnInviteActionSuccess -> Unit
}.exhaustive }.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) { private fun handleShowPowerLevelAdminWarning(event: RoomMemberProfileViewEvents.ShowPowerLevelValidation) {
EditPowerLevelDialogs.showValidation(requireActivity()) { EditPowerLevelDialogs.showValidation(requireActivity()) {
viewModel.handle(RoomMemberProfileAction.SetPowerLevel(event.currentValue, event.newValue, false)) viewModel.handle(RoomMemberProfileAction.SetPowerLevel(event.currentValue, event.newValue, false))

View File

@ -31,6 +31,7 @@ sealed class RoomMemberProfileViewEvents : VectorViewEvents {
object OnKickActionSuccess : RoomMemberProfileViewEvents() object OnKickActionSuccess : RoomMemberProfileViewEvents()
object OnBanActionSuccess : RoomMemberProfileViewEvents() object OnBanActionSuccess : RoomMemberProfileViewEvents()
data class ShowPowerLevelValidation(val currentValue: Int, val newValue: Int) : RoomMemberProfileViewEvents() data class ShowPowerLevelValidation(val currentValue: Int, val newValue: Int) : RoomMemberProfileViewEvents()
data class ShowPowerLevelDemoteWarning(val currentValue: Int, val newValue: Int) : RoomMemberProfileViewEvents()
data class StartVerification( data class StartVerification(
val userId: String, val userId: String,

View File

@ -158,6 +158,8 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
val myPowerLevel = PowerLevelsHelper(currentPowerLevelsContent).getUserPowerLevelValue(session.myUserId) val myPowerLevel = PowerLevelsHelper(currentPowerLevelsContent).getUserPowerLevelValue(session.myUserId)
if (action.askForValidation && action.newValue >= myPowerLevel) { if (action.askForValidation && action.newValue >= myPowerLevel) {
_viewEvents.post(RoomMemberProfileViewEvents.ShowPowerLevelValidation(action.previousValue, action.newValue)) _viewEvents.post(RoomMemberProfileViewEvents.ShowPowerLevelValidation(action.previousValue, action.newValue))
} else if (state.isMine) {
_viewEvents.post(RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning(action.previousValue, action.newValue))
} else { } else {
currentPowerLevelsContent.users[state.userId] = action.newValue currentPowerLevelsContent.users[state.userId] = action.newValue
viewModelScope.launch { viewModelScope.launch {

View File

@ -82,4 +82,15 @@ object EditPowerLevelDialogs {
.setNegativeButton(R.string.no, null) .setNegativeButton(R.string.no, null)
.show() .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()
}
} }

View File

@ -479,6 +479,10 @@
<string name="room_participants_action_devices_list">Show Session List</string> <string name="room_participants_action_devices_list">Show Session List</string>
<string name="room_participants_power_level_prompt">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?</string> <string name="room_participants_power_level_prompt">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?</string>
<string name="room_participants_power_level_demote_warning_title">Demote yourself?</string>
<string name="room_participants_power_level_demote_warning_prompt">"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."</string>
<string name="room_participants_power_level_demote">Demote</string>
<string name="room_participants_action_ignore_title">Ignore user</string> <string name="room_participants_action_ignore_title">Ignore user</string>
<string name="room_participants_action_ignore_prompt_msg">Ignoring this user will remove their messages from rooms you share.\n\nYou can reverse this action at any time in the general settings.</string> <string name="room_participants_action_ignore_prompt_msg">Ignoring this user will remove their messages from rooms you share.\n\nYou can reverse this action at any time in the general settings.</string>