Merge pull request #1683 from matrix-org/t3chguy/memberinfo_warn_demote_self
small refactor && warn on self-demotion
This commit is contained in:
commit
c61d09464a
2 changed files with 50 additions and 32 deletions
|
@ -440,40 +440,57 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
const roomId = this.props.member.roomId;
|
const roomId = this.props.member.roomId;
|
||||||
const target = this.props.member.userId;
|
const target = this.props.member.userId;
|
||||||
const room = this.props.matrixClient.getRoom(roomId);
|
const room = this.props.matrixClient.getRoom(roomId);
|
||||||
const self = this;
|
if (!room) return;
|
||||||
if (!room) {
|
|
||||||
return;
|
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
|
||||||
}
|
if (!powerLevelEvent) return;
|
||||||
const powerLevelEvent = room.currentState.getStateEvents(
|
|
||||||
"m.room.power_levels", "",
|
if (!powerLevelEvent.getContent().users) {
|
||||||
);
|
|
||||||
if (!powerLevelEvent) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (powerLevelEvent.getContent().users) {
|
|
||||||
const myPower = powerLevelEvent.getContent().users[this.props.matrixClient.credentials.userId];
|
|
||||||
if (parseInt(myPower) === parseInt(powerLevel)) {
|
|
||||||
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
|
||||||
Modal.createTrackedDialog('Promote to PL100 Warning', '', QuestionDialog, {
|
|
||||||
title: _t("Warning!"),
|
|
||||||
description:
|
|
||||||
<div>
|
|
||||||
{ _t("You will not be able to undo this change as you are promoting the user to have the same power level as yourself.") }<br />
|
|
||||||
{ _t("Are you sure?") }
|
|
||||||
</div>,
|
|
||||||
button: _t("Continue"),
|
|
||||||
onFinished: function(confirmed) {
|
|
||||||
if (confirmed) {
|
|
||||||
self._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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!"),
|
||||||
|
description:
|
||||||
|
<div>
|
||||||
|
{ _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.") }<br />
|
||||||
|
{ _t("Are you sure?") }
|
||||||
|
</div>,
|
||||||
|
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:
|
||||||
|
<div>
|
||||||
|
{ _t("You will not be able to undo this change as you are promoting the user to have the same power level as yourself.") }<br />
|
||||||
|
{ _t("Are you sure?") }
|
||||||
|
</div>,
|
||||||
|
button: _t("Continue"),
|
||||||
|
onFinished: (confirmed) => {
|
||||||
|
if (confirmed) {
|
||||||
|
this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
||||||
},
|
},
|
||||||
|
|
||||||
onNewDMClick: function() {
|
onNewDMClick: function() {
|
||||||
|
|
|
@ -273,6 +273,7 @@
|
||||||
"Failed to toggle moderator status": "Failed to toggle moderator status",
|
"Failed to toggle moderator status": "Failed to toggle moderator status",
|
||||||
"Failed to change power level": "Failed to change power level",
|
"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 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?",
|
"Are you sure?": "Are you sure?",
|
||||||
"No devices with registered encryption keys": "No devices with registered encryption keys",
|
"No devices with registered encryption keys": "No devices with registered encryption keys",
|
||||||
"Devices": "Devices",
|
"Devices": "Devices",
|
||||||
|
|
Loading…
Reference in a new issue