From 03f19eba556ec18ad36d2244ce109b58ac80ff07 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 5 Feb 2016 14:38:28 +0000 Subject: [PATCH] Implement radio boxes ( vector-im/vector-web#731 ) for history visibility. Hook up remaining bits. --- src/components/structures/RoomView.js | 4 +- src/components/views/rooms/RoomSettings.js | 76 ++++++++++++++++++---- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 83dc1c3631..5a3dcbd094 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -1222,15 +1222,15 @@ module.exports = React.createClass({ this.refs.room_settings.setTopic(this.refs.header.getTopic()); this.refs.room_settings.save().then((results) => { - console.log("Settings saved."); var fails = results.filter(function(result) { return result.state !== "fulfilled" }); + console.log("Settings saved with %s errors", fails.length); if (fails.length) { fails.forEach(function(result) { console.error(result.reason); }); var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); Modal.createDialog(ErrorDialog, { - title: "Failed to set state", + title: "Failed to save settings", description: fails.map(function(result) { return result.reason }).join("\n"), }); // still editing room settings diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index 6153ccbc2c..3642fbca42 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -102,12 +102,31 @@ module.exports = React.createClass({ promises.push(MatrixClientPeg.get().setRoomTopic(roomId, this.state.topic)); } - // TODO: - // this.state.join_rule - // this.state.history_visibility - // this.state.guest_access + if (this.state.history_visibility !== originalState.history_visibility) { + promises.push(MatrixClientPeg.get().sendStateEvent( + roomId, "m.room.history_visibility", + { history_visibility: this.state.history_visibility }, + "" + )); + } + + if (this.state.join_rule !== originalState.join_rule) { + promises.push(MatrixClientPeg.get().sendStateEvent( + roomId, "m.room.join_rules", + { join_rule: this.state.join_rule }, + "" + )); + } + + if (this.state.guest_access !== originalState.guest_access) { + promises.push(MatrixClientPeg.get().sendStateEvent( + roomId, "m.room.guest_access", + { guest_access: this.state.guest_access }, + "" + )); + } + - // setRoomMutePushRule if (this.state.areNotifsMuted !== originalState.areNotifsMuted) { promises.push(MatrixClientPeg.get().setRoomMutePushRule( "global", roomId, this.state.areNotifsMuted @@ -144,6 +163,7 @@ module.exports = React.createClass({ } }); } + console.log("Performing %s operations", promises.length); // color scheme promises.push(this.saveColor()); @@ -204,6 +224,12 @@ module.exports = React.createClass({ } return event.getContent()[keyName] || defaultValue; }, + + _onHistoryRadioToggle: function(ev) { + this.setState({ + history_visibility: ev.target.value + }); + }, _onToggle: function(keyName, checkedValue, uncheckedValue, ev) { console.log("Checkbox toggle: %s %s", keyName, ev.target.checked); @@ -386,6 +412,10 @@ module.exports = React.createClass({ } + // If there is no history_visibility, it is assumed to be 'shared'. + // http://matrix.org/docs/spec/r0.0.0/client_server.html#id31 + var historyVisibility = this.state.history_visibility || "shared"; + // FIXME: disable guests_read if the user hasn't turned on shared history return (
@@ -402,20 +432,38 @@ module.exports = React.createClass({ defaultChecked={this.state.join_rule !== "public"}/> Make this room private - - +
+

Who can read history?

+ + + + +