Show confirm dialog when change your own power level
authorAjay Bura <ajbura@gmail.com>
Tue, 1 Feb 2022 04:11:50 +0000 (09:41 +0530)
committerAjay Bura <ajbura@gmail.com>
Tue, 1 Feb 2022 04:11:50 +0000 (09:41 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/organisms/profile-viewer/ProfileViewer.jsx

index 3af19c29b02d4e1adb40ac288e92294606d1092c..34530122ed869bde610c759c3c62bfd7c2c178f3 100644 (file)
@@ -371,10 +371,16 @@ function ProfileViewer() {
 
     const handleChangePowerLevel = (newPowerLevel) => {
       if (newPowerLevel === powerLevel) return;
-      if (newPowerLevel === myPowerLevel
-        ? 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?')
-        : true
-      ) {
+      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?';
+      const DEMOTING_MYSELF_MSG = 'You will not be able to undo this change as you are demoting yourself. Are you sure?';
+
+      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);
       }
     };