Show confirm dialog when change your own power level

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-02-01 09:41:50 +05:30
parent e4571bf668
commit b155d7d1ba

View file

@ -371,10 +371,16 @@ function ProfileViewer() {
const handleChangePowerLevel = (newPowerLevel) => { const handleChangePowerLevel = (newPowerLevel) => {
if (newPowerLevel === powerLevel) return; if (newPowerLevel === powerLevel) return;
if (newPowerLevel === myPowerLevel const SHARED_POWER_MSG = 'You will not be able to undo this change as you are promoting the user to have the same power level as yourself. Are you sure?';
? confirm('You will not be able to undo this change as you are promoting the user to have the same power level as yourself. Are you sure?') const DEMOTING_MYSELF_MSG = 'You will not be able to undo this change as you are demoting yourself. Are you sure?';
: true
) { const isSharedPower = newPowerLevel === myPowerLevel;
const isDemotingMyself = userId === mx.getUserId();
if (isSharedPower || isDemotingMyself) {
if (confirm(isSharedPower ? SHARED_POWER_MSG : DEMOTING_MYSELF_MSG)) {
roomActions.setPowerLevel(roomId, userId, newPowerLevel);
}
} else {
roomActions.setPowerLevel(roomId, userId, newPowerLevel); roomActions.setPowerLevel(roomId, userId, newPowerLevel);
} }
}; };