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

@ -102,6 +102,7 @@ class RoomMemberProfileFragment @Inject constructor(
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
@ -111,6 +112,12 @@ class RoomMemberProfileFragment @Inject constructor(
}
}
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))

View file

@ -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,

View file

@ -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 {

View file

@ -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()
}
}

View file

@ -479,6 +479,10 @@
<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_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_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>