mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 19:05:56 +03:00
Power level: warn when demoting yourself
This commit is contained in:
parent
a8ae4ddde8
commit
bf5ad2cf18
5 changed files with 35 additions and 10 deletions
|
@ -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))
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue