From 9085a2a8664fc06b881cd127736e7ac9163c75cc Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 1 Mar 2016 18:23:57 +0000 Subject: [PATCH] Pass room metadata from 3pid invite emails all the way through to the relevant components so we can display it. --- src/components/structures/MatrixChat.js | 29 ++++++++- src/components/structures/RoomView.js | 15 ++++- src/components/views/avatars/RoomAvatar.js | 28 +++++++-- src/components/views/rooms/RoomHeader.js | 68 ++++++++++++---------- 4 files changed, 102 insertions(+), 38 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 8a0f36e483..e3a6abb1a4 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -312,7 +312,10 @@ module.exports = React.createClass({ }); break; case 'view_room': - this._viewRoom(payload.room_id, payload.show_settings, payload.event_id, payload.invite_sign_url); + this._viewRoom( + payload.room_id, payload.show_settings, payload.event_id, + payload.invite_sign_url, payload.oob_data + ); break; case 'view_prev_room': roomIndexDelta = -1; @@ -350,6 +353,7 @@ module.exports = React.createClass({ room_id: foundRoom.roomId, event_id: payload.event_id, invite_sign_url: payload.invite_sign_url, + oob_data: payload.oob_data, }); return; } @@ -361,6 +365,7 @@ module.exports = React.createClass({ room_id: result.room_id, event_id: payload.event_id, invite_sign_url: payload.invite_sign_url, + room_oob_data: payload.room_oob_data, }); }); break; @@ -448,7 +453,10 @@ module.exports = React.createClass({ // // eventId is optional and will cause a switch to the context of that // particular event. - _viewRoom: function(roomId, showSettings, eventId, invite_sign_url) { + // @param {Object} room_oob_data Object of additional data about the room + // that has been passed out-of-band (eg. + // room name and avatar from an invite email) + _viewRoom: function(roomId, showSettings, eventId, invite_sign_url, oob_data) { // before we switch room, record the scroll state of the current room this._updateScrollMap(); @@ -461,6 +469,7 @@ module.exports = React.createClass({ initialEventPixelOffset: undefined, page_type: this.PageTypes.RoomView, inviteSignUrl: invite_sign_url, + roomOobData: oob_data, }; // if we aren't given an explicit event id, look for one in the @@ -552,10 +561,12 @@ module.exports = React.createClass({ room_alias: self.starting_room_alias, event_id: self.starting_event_id, invite_sign_url: self.starting_room_invite_sign_url, + room_oob_data: self.starting_room_oob_data, }); delete self.starting_room_alias; delete self.starting_event_id; delete self.starting_room_invite_sign_url; + delete self.starting_room_oob_data; } else if (!self.state.page_type) { if (!self.state.currentRoom) { var firstRoom = null; @@ -675,6 +686,13 @@ module.exports = React.createClass({ var segments = screen.substring(5).split('/'); var roomString = segments[0]; var eventId = segments[1]; // undefined if no event id given + + var oob_data = { + name: params.room_name, + avatarUrl: params.room_avatar_url, + inviterName: params.inviter_name, + }; + if (roomString[0] == '#') { if (this.state.logged_in) { dis.dispatch({ @@ -682,11 +700,16 @@ module.exports = React.createClass({ room_alias: roomString, event_id: eventId, invite_sign_url: params.signurl, + oob_data: oob_data, }); } else { // Okay, we'll take you here soon... + // XXX: There are way too many of these: + // It would probably be better to handle whether the SDK is + // ready or not in the view_room_alias handler instead. this.starting_room_alias = roomString; this.starting_room_invite_sign_url = params.signurl; + this.starting_room_oob_data = oob_data; this.starting_event_id = eventId; // ...but you're still going to have to log in. this.notifyNewScreen('login'); @@ -697,6 +720,7 @@ module.exports = React.createClass({ room_id: roomString, event_id: eventId, invite_sign_url: params.signurl, + oob_data: oob_data, }); } } @@ -884,6 +908,7 @@ module.exports = React.createClass({ roomId={this.state.currentRoom} eventId={this.state.initialEventId} inviteSignUrl={this.state.inviteSignUrl} + oobData={this.state.roomOobData} highlightedEventId={this.state.highlightedEventId} eventPixelOffset={this.state.initialEventPixelOffset} key={this.state.currentRoom} diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 0ad372634a..8e2ededad6 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -59,6 +59,12 @@ module.exports = React.createClass({ // (given as part of the link in the invite email) inviteSignUrl: React.PropTypes.string, + // Any data about the room that would normally come from the Home Server + // but has been passed out-of-band, eg. the room name and avatar URL + // from an email invite (a workaround for the fact that we can't + // get this information from the HS using an email invite). + oobData: React.PropTypes.object, + // id of an event to jump to. If not given, will go to the end of the // live timeline. eventId: React.PropTypes.string, @@ -1052,13 +1058,19 @@ module.exports = React.createClass({ ); } else { + var inviterName = undefined; + if (this.props.oobData) { + inviterName = this.props.oobData.inviterName; + } + return (
- +
@@ -1293,6 +1305,7 @@ module.exports = React.createClass({ return (
2 keys @@ -103,14 +115,20 @@ module.exports = React.createClass({ }, getFallbackAvatar: function(props) { + if (!this.props.room) return null; + return Avatar.defaultAvatarUrlForString(props.room.roomId); }, render: function() { var BaseAvatar = sdk.getComponent("avatars.BaseAvatar"); + + var roomName = this.props.room ? this.props.room.name : this.props.oobData.name; + return ( - + ); } }); diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index 0b52281507..1b3956c62d 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.js @@ -33,6 +33,7 @@ module.exports = React.createClass({ propTypes: { room: React.PropTypes.object, + oobData: React.PropTypes.object, editing: React.PropTypes.bool, onSettingsClick: React.PropTypes.func, onSaveClick: React.PropTypes.func, @@ -217,18 +218,27 @@ module.exports = React.createClass({ } // XXX: this is a bit inefficient - we could just compare room.name for 'Empty room'... - var members = this.props.room.getJoinedMembers(); var settingsHint = false; - if (members.length === 1 && members[0].userId === MatrixClientPeg.get().credentials.userId) { - var name = this.props.room.currentState.getStateEvents('m.room.name', ''); - if (!name || !name.getContent().name) { - settingsHint = true; + var members = this.props.room ? this.props.room.getJoinedMembers() : undefined; + if (members) { + if (members.length === 1 && members[0].userId === MatrixClientPeg.get().credentials.userId) { + var name = this.props.room.currentState.getStateEvents('m.room.name', ''); + if (!name || !name.getContent().name) { + settingsHint = true; + } } } + var roomName; + if (this.props.oobData && this.props.oobData.name) { + roomName = this.props.oobData.name; + } else { + this.props.room.name; + } + name =
-
{ this.props.room.name }
+
{ roomName }
{ searchStatus }
@@ -246,36 +256,34 @@ module.exports = React.createClass({ onValueChanged={ this.onTopicChanged } initialValue={ this.state.topic }/> } else { - var topic = this.props.room.currentState.getStateEvents('m.room.topic', ''); + var topic = this.props.room ? this.props.room.currentState.getStateEvents('m.room.topic', '') : ''; if (topic) topic_el =
{ topic.getContent().topic }
; } var roomAvatar = null; - if (this.props.room) { - if (can_set_room_avatar) { - roomAvatar = ( -
-
- -
-
- - -
+ if (can_set_room_avatar) { + roomAvatar = ( +
+
+
- ); - } - else { - roomAvatar = ( -
- +
+ +
- ); - } +
+ ); + } + else { + roomAvatar = ( +
+ +
+ ); } var leave_button;