From f67d405732f4a93b8da493a49947e501a0809ddb Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Tue, 2 Jan 2018 23:15:36 +0000
Subject: [PATCH 1/3] small refactor && warn on self-demotion
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
---
src/components/views/rooms/MemberInfo.js | 50 +++++++++++++++---------
src/i18n/strings/en_EN.json | 1 +
2 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js
index cb6cb6c0f3..9ea749c98e 100644
--- a/src/components/views/rooms/MemberInfo.js
+++ b/src/components/views/rooms/MemberInfo.js
@@ -440,20 +440,35 @@ module.exports = withMatrixClient(React.createClass({
const roomId = this.props.member.roomId;
const target = this.props.member.userId;
const room = this.props.matrixClient.getRoom(roomId);
- const self = this;
- if (!room) {
- return;
- }
- const powerLevelEvent = room.currentState.getStateEvents(
- "m.room.power_levels", "",
- );
- if (!powerLevelEvent) {
- return;
- }
+ if (!room) return;
+
+ const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
+ if (!powerLevelEvent) return;
+
if (powerLevelEvent.getContent().users) {
- const myPower = powerLevelEvent.getContent().users[this.props.matrixClient.credentials.userId];
+ const myUserId = this.props.matrixClient.getUserId();
+ const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
+
+ if (myUserId === target) {
+ Modal.createTrackedDialog('Demoting Self', '', QuestionDialog, {
+ title: _t("Warning!"),
+ description:
+
+ { _t("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.") }
+ { _t("Are you sure?") }
+
,
+ button: _t("Continue"),
+ onFinished: (confirmed) => {
+ if (confirmed) {
+ this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
+ }
+ },
+ });
+ return;
+ }
+
+ const myPower = powerLevelEvent.getContent().users[myUserId];
if (parseInt(myPower) === parseInt(powerLevel)) {
- const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
Modal.createTrackedDialog('Promote to PL100 Warning', '', QuestionDialog, {
title: _t("Warning!"),
description:
@@ -462,18 +477,17 @@ module.exports = withMatrixClient(React.createClass({
{ _t("Are you sure?") }
,
button: _t("Continue"),
- onFinished: function(confirmed) {
+ onFinished: (confirmed) => {
if (confirmed) {
- self._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
+ this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
}
},
});
- } else {
- this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
+ return;
}
- } else {
- this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
+
}
+ this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
},
onNewDMClick: function() {
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json
index f28322398c..9cf60461cc 100644
--- a/src/i18n/strings/en_EN.json
+++ b/src/i18n/strings/en_EN.json
@@ -273,6 +273,7 @@
"Failed to toggle moderator status": "Failed to toggle moderator status",
"Failed to change power level": "Failed to change power level",
"You will not be able to undo this change as you are promoting the user to have the same power level as yourself.": "You will not be able to undo this change as you are promoting the user to have the same power level as yourself.",
+ "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.": "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.",
"Are you sure?": "Are you sure?",
"No devices with registered encryption keys": "No devices with registered encryption keys",
"Devices": "Devices",
From a473971c7b6f84b8b16717883045b18248057265 Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Fri, 5 Jan 2018 11:11:20 +0000
Subject: [PATCH 2/3] negate for less indentation
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
---
src/components/views/rooms/MemberInfo.js | 78 ++++++++++++------------
1 file changed, 40 insertions(+), 38 deletions(-)
diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js
index 9ea749c98e..5afd0a4a64 100644
--- a/src/components/views/rooms/MemberInfo.js
+++ b/src/components/views/rooms/MemberInfo.js
@@ -445,47 +445,49 @@ module.exports = withMatrixClient(React.createClass({
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
if (!powerLevelEvent) return;
- if (powerLevelEvent.getContent().users) {
- const myUserId = this.props.matrixClient.getUserId();
- const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
+ if (!powerLevelEvent.getContent().users) {
+ this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
+ return;
+ }
- if (myUserId === target) {
- Modal.createTrackedDialog('Demoting Self', '', QuestionDialog, {
- title: _t("Warning!"),
- description:
-
- { _t("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.") }
- { _t("Are you sure?") }
-
,
- button: _t("Continue"),
- onFinished: (confirmed) => {
- if (confirmed) {
- this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
- }
- },
- });
- return;
- }
+ const myUserId = this.props.matrixClient.getUserId();
+ const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
- const myPower = powerLevelEvent.getContent().users[myUserId];
- if (parseInt(myPower) === parseInt(powerLevel)) {
- Modal.createTrackedDialog('Promote to PL100 Warning', '', QuestionDialog, {
- title: _t("Warning!"),
- description:
-
- { _t("You will not be able to undo this change as you are promoting the user to have the same power level as yourself.") }
- { _t("Are you sure?") }
-
,
- button: _t("Continue"),
- onFinished: (confirmed) => {
- if (confirmed) {
- this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
- }
- },
- });
- return;
- }
+ if (myUserId === target) {
+ Modal.createTrackedDialog('Demoting Self', '', QuestionDialog, {
+ title: _t("Warning!"),
+ description:
+
+ { _t("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.") }
+ { _t("Are you sure?") }
+
,
+ button: _t("Continue"),
+ onFinished: (confirmed) => {
+ if (confirmed) {
+ this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
+ }
+ },
+ });
+ return;
+ }
+ const myPower = powerLevelEvent.getContent().users[myUserId];
+ if (parseInt(myPower) === parseInt(powerLevel)) {
+ Modal.createTrackedDialog('Promote to PL100 Warning', '', QuestionDialog, {
+ title: _t("Warning!"),
+ description:
+
+ { _t("You will not be able to undo this change as you are promoting the user to have the same power level as yourself.") }
+ { _t("Are you sure?") }
+
,
+ button: _t("Continue"),
+ onFinished: (confirmed) => {
+ if (confirmed) {
+ this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
+ }
+ },
+ });
+ return;
}
this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
},
From a8bd4bf858370f31d1f1193086ce66f3cac1352b Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Fri, 5 Jan 2018 11:55:43 +0000
Subject: [PATCH 3/3] add comment
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
---
src/components/views/rooms/MemberInfo.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js
index 5afd0a4a64..688f1084b6 100644
--- a/src/components/views/rooms/MemberInfo.js
+++ b/src/components/views/rooms/MemberInfo.js
@@ -453,6 +453,7 @@ module.exports = withMatrixClient(React.createClass({
const myUserId = this.props.matrixClient.getUserId();
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
+ // If we are changing our own PL it can only ever be decreasing, which we cannot reverse.
if (myUserId === target) {
Modal.createTrackedDialog('Demoting Self', '', QuestionDialog, {
title: _t("Warning!"),