From 8cfb0e9ef45436a4f2981a2f2d01507dd3911239 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Tue, 22 Mar 2016 00:57:40 +0000 Subject: [PATCH 1/3] rework roomsettings for new visibility UI --- src/components/views/rooms/RoomSettings.js | 123 +++++++++++++++++---- 1 file changed, 101 insertions(+), 22 deletions(-) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index af48277bb62..2b933cd57a6 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -55,9 +55,20 @@ module.exports = React.createClass({ power_levels_changed: false, tags_changed: false, tags: tags, - areNotifsMuted: areNotifsMuted + areNotifsMuted: areNotifsMuted, }; }, + + componentWillMount: function() { + var self = this; + MatrixClientPeg.get().getRoomVisibility( + this.props.room.roomId + ).done((result) => { + self.setState({ isRoomPublished: result.visibility === "public" }); + }, (err) => { + console.error("Failed to get room visibility: " + err); + }); + }, setName: function(name) { this.setState({ @@ -112,6 +123,13 @@ module.exports = React.createClass({ )); } + if (this.state.isRoomPublished !== originalState.isRoomPublished) { + promises.push(MatrixClientPeg.get().setRoomVisibility( + roomId, + this.state.isRoomPublished ? "public" : "private" + )); + } + if (this.state.join_rule !== originalState.join_rule) { promises.push(MatrixClientPeg.get().sendStateEvent( roomId, "m.room.join_rules", @@ -252,6 +270,30 @@ module.exports = React.createClass({ }); }, + _onRoomAccessRadioToggle: function(ev) { + var self = this; + switch (ev.target.value) { + case "invite_only": + self.setState({ + join_rule: "invite", + guest_access: "can_join", + }); + break; + case "public_no_guests": + self.setState({ + join_rule: "public", + guest_access: "forbidden", + }); + break; + case "public_with_guests": + self.setState({ + join_rule: "public", + guest_access: "can_join", + }); + break; + } + }, + _onToggle: function(keyName, checkedValue, uncheckedValue, ev) { console.log("Checkbox toggle: %s %s", keyName, ev.target.checked); var state = {}; @@ -427,7 +469,20 @@ module.exports = React.createClass({ // 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 + var addressWarning; + var aliasEvents = this.props.room.currentState.getStateEvents('m.room.aliases') || []; + var aliasCount = 0; + aliasEvents.forEach((event) => { + aliasCount += event.getContent().aliases.length; + }); + + if (this.state.join_rule === "public" && aliasCount == 0) { + addressWarning = +
+ To link to a room it must have an address. +
+ } + return (
@@ -440,43 +495,65 @@ module.exports = React.createClass({ defaultChecked={this.state.areNotifsMuted}/> Mute notifications for this room - - +
+

Who can access this room?

+ + + + { addressWarning } +
+ +

Who can read history?

- - - -
+ + Date: Tue, 22 Mar 2016 12:10:58 +0000 Subject: [PATCH 2/3] incorporate PR review, and explicitly spell out if the room has ended up with guest_access=forbidden but join_rules=invite --- src/components/views/rooms/RoomSettings.js | 42 ++++++++++++++++------ 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index 2b933cd57a6..bbe90ee0593 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -56,15 +56,15 @@ module.exports = React.createClass({ tags_changed: false, tags: tags, areNotifsMuted: areNotifsMuted, + isRoomPublished: false, // updated in componentWillMount }; }, componentWillMount: function() { - var self = this; - MatrixClientPeg.get().getRoomVisibility( + MatrixClientPeg.get().getRoomDirectoryVisibility( this.props.room.roomId ).done((result) => { - self.setState({ isRoomPublished: result.visibility === "public" }); + this.setState({ isRoomPublished: result.visibility === "public" }); }, (err) => { console.error("Failed to get room visibility: " + err); }); @@ -124,7 +124,7 @@ module.exports = React.createClass({ } if (this.state.isRoomPublished !== originalState.isRoomPublished) { - promises.push(MatrixClientPeg.get().setRoomVisibility( + promises.push(MatrixClientPeg.get().setRoomDirectoryVisibility( roomId, this.state.isRoomPublished ? "public" : "private" )); @@ -271,22 +271,30 @@ module.exports = React.createClass({ }, _onRoomAccessRadioToggle: function(ev) { - var self = this; + + // join_rule + // INVITE | PUBLIC + // ----------------------+---------------- + // guest CAN_JOIN | inv_only | pub_with_guest + // access ----------------------+---------------- + // FORBIDDEN | inv_only | pub_no_guest + // ----------------------+---------------- + switch (ev.target.value) { case "invite_only": - self.setState({ + this.setState({ join_rule: "invite", guest_access: "can_join", }); break; case "public_no_guests": - self.setState({ + this.setState({ join_rule: "public", guest_access: "forbidden", }); break; case "public_with_guests": - self.setState({ + this.setState({ join_rule: "public", guest_access: "can_join", }); @@ -483,6 +491,17 @@ module.exports = React.createClass({
} + var inviteGuestWarning; + if (this.state.join_rule !== "public" && this.state.guest_access === "forbidden") { + inviteGuestWarning = +
+ Guests cannot join this room even if explicitly invited. { + this.setState({ join_rule: "invite", guest_access: "can_join" }); + e.preventDefault(); + }}>Click here to fix. +
+ } + return (
@@ -497,11 +516,12 @@ module.exports = React.createClass({

Who can access this room?

+ { inviteGuestWarning } { addressWarning } From 5a2a2c5bdc3f51bc64fb44669b01de18aa12de1e Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Tue, 22 Mar 2016 12:26:38 +0000 Subject: [PATCH 3/3] fix up and factor out mayChangeRoomAccess and fix review feedback --- src/components/views/rooms/RoomSettings.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index bbe90ee0593..74b326e9877 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -56,7 +56,7 @@ module.exports = React.createClass({ tags_changed: false, tags: tags, areNotifsMuted: areNotifsMuted, - isRoomPublished: false, // updated in componentWillMount + // isRoomPublished: // set in componentWillMount }; }, @@ -284,6 +284,11 @@ module.exports = React.createClass({ case "invite_only": this.setState({ join_rule: "invite", + // we always set guests can_join here as it makes no sense to have + // an invite-only room that guests can't join. If you explicitly + // invite them, you clearly want them to join, whether they're a + // guest or not. In practice, guest_access should probably have + // been implemented as part of the join_rules enum. guest_access: "can_join", }); break; @@ -330,6 +335,13 @@ module.exports = React.createClass({ }); }, + mayChangeRoomAccess: function() { + var cli = MatrixClientPeg.get(); + var roomState = this.props.room.currentState; + return (roomState.mayClientSendStateEvent("m.room.join_rules", cli) && + roomState.mayClientSendStateEvent("m.room.guest_access", cli)) + }, + render: function() { // TODO: go through greying out things you don't have permission to change // (or turning them into informative stuff) @@ -519,23 +531,21 @@ module.exports = React.createClass({ { inviteGuestWarning }