From 3a7ebf73eb2e572524d9ad032b808364132be7a6 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 20 Jul 2015 17:31:40 +0100 Subject: [PATCH] Wire up changing of power levels --- skins/base/views/molecules/RoomSettings.js | 49 ++++++++++++++++++---- skins/base/views/organisms/RoomView.js | 7 ++++ src/controllers/molecules/RoomSettings.js | 6 +++ 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/skins/base/views/molecules/RoomSettings.js b/skins/base/views/molecules/RoomSettings.js index 358764c6..14197154 100644 --- a/skins/base/views/molecules/RoomSettings.js +++ b/skins/base/views/molecules/RoomSettings.js @@ -37,6 +37,33 @@ module.exports = React.createClass({ return this.refs.share_history.getDOMNode().checked ? "shared" : "invited"; }, + getPowerLevels: function() { + if (!this.state.power_levels_changed) return undefined; + + var power_levels = this.props.room.currentState.getStateEvents('m.room.power_levels', ''); + power_levels = power_levels.getContent(); + + var new_power_levels = { + ban: parseInt(this.refs.ban.getDOMNode().value), + kick: parseInt(this.refs.kick.getDOMNode().value), + redact: parseInt(this.refs.redact.getDOMNode().value), + invite: parseInt(this.refs.invite.getDOMNode().value), + events_default: parseInt(this.refs.events_default.getDOMNode().value), + state_default: parseInt(this.refs.state_default.getDOMNode().value), + users_default: parseInt(this.refs.users_default.getDOMNode().value), + users: power_levels.users, + events: power_levels.events, + }; + + return new_power_levels; + }, + + onPowerLevelsChanged: function() { + this.setState({ + power_levels_changed: true + }); + }, + render: function() { var topic = this.props.room.currentState.getStateEvents('m.room.topic', ''); if (topic) topic = topic.getContent().topic; @@ -83,31 +110,39 @@ module.exports = React.createClass({
- +
- +
- +
- +
- +
- +
- +
diff --git a/skins/base/views/organisms/RoomView.js b/skins/base/views/organisms/RoomView.js index 62c750bf..56699165 100644 --- a/skins/base/views/organisms/RoomView.js +++ b/skins/base/views/organisms/RoomView.js @@ -50,6 +50,7 @@ module.exports = React.createClass({ var new_topic = this.refs.room_settings.getTopic(); var new_join_rule = this.refs.room_settings.getJoinRules(); var new_history_visibility = this.refs.room_settings.getHistoryVisibility(); + var new_power_levels = this.refs.room_settings.getPowerLevels(); var old_name = this.state.room.name; @@ -98,6 +99,12 @@ module.exports = React.createClass({ }, "" ); } + + if (new_power_levels) { + MatrixClientPeg.get().sendStateEvent( + this.state.room.roomId, "m.room.power_levels", new_power_levels, "" + ); + } }, render: function() { diff --git a/src/controllers/molecules/RoomSettings.js b/src/controllers/molecules/RoomSettings.js index 546290ee..fe7cd634 100644 --- a/src/controllers/molecules/RoomSettings.js +++ b/src/controllers/molecules/RoomSettings.js @@ -22,4 +22,10 @@ module.exports = { propTypes: { room: React.PropTypes.object.isRequired, }, + + getInitialState: function() { + return { + power_levels_changed: false + }; + } };