From 59f599af5c78a3c3d7d826a052e45f34df9f51aa Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Mon, 21 Mar 2016 00:49:18 +0000 Subject: [PATCH] prompt before giving equal ops --- .../views/elements/PowerSelector.js | 10 ++- src/components/views/rooms/MemberInfo.js | 67 ++++++++++++++----- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/components/views/elements/PowerSelector.js b/src/components/views/elements/PowerSelector.js index 118ade8151..7456156df3 100644 --- a/src/components/views/elements/PowerSelector.js +++ b/src/components/views/elements/PowerSelector.js @@ -85,14 +85,20 @@ module.exports = React.createClass({ customPicker = of { input }; } - var selectValue = roles[this.props.value] || "Custom"; + var selectValue; + if (this.state.custom) { + selectValue = "Custom"; + } + else { + selectValue = roles[this.props.value] || "Custom"; + } var select; if (this.props.disabled) { select = { selectValue }; } else { select = - diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js index a847c5e156..196e3e4c5f 100644 --- a/src/components/views/rooms/MemberInfo.js +++ b/src/components/views/rooms/MemberInfo.js @@ -179,22 +179,7 @@ module.exports = React.createClass({ this.props.onFinished(); }, - onPowerChange: function(powerLevel) { - var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - var roomId = this.props.member.roomId; - var target = this.props.member.userId; - var room = MatrixClientPeg.get().getRoom(roomId); - if (!room) { - this.props.onFinished(); - return; - } - var powerLevelEvent = room.currentState.getStateEvents( - "m.room.power_levels", "" - ); - if (!powerLevelEvent) { - this.props.onFinished(); - return; - } + _applyPowerChange: function(roomId, target, powerLevel, powerLevelEvent) { MatrixClientPeg.get().setPowerLevel(roomId, target, parseInt(powerLevel), powerLevelEvent).done( function() { // NO-OP; rely on the m.room.member event coming down else we could @@ -207,7 +192,55 @@ module.exports = React.createClass({ }); } ); - this.props.onFinished(); + this.props.onFinished(); + }, + + onPowerChange: function(powerLevel) { + var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + var roomId = this.props.member.roomId; + var target = this.props.member.userId; + var room = MatrixClientPeg.get().getRoom(roomId); + var self = this; + if (!room) { + this.props.onFinished(); + return; + } + var powerLevelEvent = room.currentState.getStateEvents( + "m.room.power_levels", "" + ); + if (!powerLevelEvent) { + this.props.onFinished(); + return; + } + if (powerLevelEvent.getContent().users) { + var myPower = powerLevelEvent.getContent().users[MatrixClientPeg.get().credentials.userId]; + if (parseInt(myPower) === parseInt(powerLevel)) { + var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); + Modal.createDialog(QuestionDialog, { + title: "Warning", + description: +
+ 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? +
, + button: "Continue", + onFinished: function(confirmed) { + if (confirmed) { + self._applyPowerChange(roomId, target, powerLevel, powerLevelEvent); + } + else { + self.props.onFinished(); + } + }, + }); + } + else { + this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent); + } + } + else { + this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent); + } }, onChatClick: function() {