mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-05 05:38:41 +03:00
factor out warn self demote and apply to muting yourself
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
e858cf3bcb
commit
b97aa77aca
1 changed files with 37 additions and 16 deletions
|
@ -332,13 +332,42 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onMuteToggle: function() {
|
_warnSelfDemote: function() {
|
||||||
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
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: resolve,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onMuteToggle: async function() {
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
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);
|
||||||
if (!room) return;
|
if (!room) return;
|
||||||
|
|
||||||
|
// if muting self, warn as it may be irreversible
|
||||||
|
if (target === this.props.matrixClient.getUserId()) {
|
||||||
|
try {
|
||||||
|
if (!await this._warnSelfDemote()) return;
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to warn about self demotion: ", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
|
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
|
||||||
if (!powerLevelEvent) return;
|
if (!powerLevelEvent) return;
|
||||||
|
|
||||||
|
@ -436,7 +465,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
}).done();
|
}).done();
|
||||||
},
|
},
|
||||||
|
|
||||||
onPowerChange: function(powerLevel) {
|
onPowerChange: async function(powerLevel) {
|
||||||
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);
|
||||||
|
@ -455,20 +484,12 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
|
|
||||||
// If we are changing our own PL it can only ever be decreasing, which we cannot reverse.
|
// If we are changing our own PL it can only ever be decreasing, which we cannot reverse.
|
||||||
if (myUserId === target) {
|
if (myUserId === target) {
|
||||||
Modal.createTrackedDialog('Demoting Self', '', QuestionDialog, {
|
try {
|
||||||
title: _t("Warning!"),
|
if (!await this._warnSelfDemote()) return;
|
||||||
description:
|
this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
||||||
<div>
|
} catch (e) {
|
||||||
{ _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 />
|
console.error("Failed to warn about self demotion: ", e);
|
||||||
{ _t("Are you sure?") }
|
}
|
||||||
</div>,
|
|
||||||
button: _t("Continue"),
|
|
||||||
onFinished: (confirmed) => {
|
|
||||||
if (confirmed) {
|
|
||||||
this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue