From d9e8292a5e1fe8805e3e07718fef957588902ebd Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 14 Aug 2017 14:06:54 +0100 Subject: [PATCH 1/3] Revert "At /user, view member of current room" --- src/components/structures/LoggedInView.js | 4 +-- src/components/structures/MatrixChat.js | 44 ++++++----------------- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/src/components/structures/LoggedInView.js b/src/components/structures/LoggedInView.js index 0790a5766e..093fae5d7b 100644 --- a/src/components/structures/LoggedInView.js +++ b/src/components/structures/LoggedInView.js @@ -301,13 +301,13 @@ export default React.createClass({ case PageTypes.UserView: page_element = null; // deliberately null for now - right_panel = ; + right_panel = ; break; case PageTypes.GroupView: page_element = ; - //right_panel = ; + //right_panel = ; break; } diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 930c618f7a..6fdec80f38 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -448,7 +448,6 @@ module.exports = React.createClass({ }); }, 0); } - this.notifyNewScreen('user/' + payload.member.userId); break; case 'view_room': // Takes either a room ID or room alias: if switching to a room the client is already @@ -1204,44 +1203,21 @@ module.exports = React.createClass({ } else if (screen.indexOf('user/') == 0) { const userId = screen.substring(5); - // Wait for the first sync so that `getRoom` gives us a room object if it's - // in the sync response - const waitFor = this.firstSyncPromise ? - this.firstSyncPromise.promise : Promise.resolve(); - waitFor.then(() => { - if (params.action === 'chat') { - this._chatCreateOrReuse(userId); - return; - } + if (params.action === 'chat') { + this._chatCreateOrReuse(userId); + return; + } - // Get the member object for the current room, if a current room is set or - // we have a last_room in localStorage. The user might not be a member of - // this room (in which case member will be falsey). - let member; - const roomId = this.state.currentRoomId || localStorage.getItem('mx_last_room_id'); - if (roomId) { - const room = MatrixClientPeg.get().getRoom(roomId); - if (room) { - member = room.getMember(userId); - } - } - - if (member) { - // This user is a member of this room, so view the room - dis.dispatch({ - action: 'view_room', - room_id: roomId, - }); - } else { - // This user is not a member of this room, show the user view - member = new Matrix.RoomMember(null, userId); - this._setPage(PageTypes.UserView); - } + this.setState({ viewUserId: userId }); + this._setPage(PageTypes.UserView); + this.notifyNewScreen('user/' + userId); + const member = new Matrix.RoomMember(null, userId); + if (member) { dis.dispatch({ action: 'view_user', member: member, }); - }); + } } else if (screen.indexOf('group/') == 0) { const groupId = screen.substring(6); From b59de7964cd06f8b846e1b50f6f41384f319494b Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 14 Aug 2017 14:37:49 +0100 Subject: [PATCH 2/3] Wait for first sync before dispatching view_user on /user the RightPanel will be mounted once we're done doing the first sync, so wait until then and then dispatch a view_user. This is not very nice but it's what we do for view_room. --- src/components/structures/LoggedInView.js | 4 ++-- src/components/structures/MatrixChat.js | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/structures/LoggedInView.js b/src/components/structures/LoggedInView.js index 093fae5d7b..0790a5766e 100644 --- a/src/components/structures/LoggedInView.js +++ b/src/components/structures/LoggedInView.js @@ -301,13 +301,13 @@ export default React.createClass({ case PageTypes.UserView: page_element = null; // deliberately null for now - right_panel = ; + right_panel = ; break; case PageTypes.GroupView: page_element = ; - //right_panel = ; + //right_panel = ; break; } diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 6fdec80f38..a512d60509 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1203,21 +1203,22 @@ module.exports = React.createClass({ } else if (screen.indexOf('user/') == 0) { const userId = screen.substring(5); - if (params.action === 'chat') { - this._chatCreateOrReuse(userId); - return; - } + const waitFor = this.firstSyncPromise ? + this.firstSyncPromise.promise : Promise.resolve(); + waitFor.then(() => { + if (params.action === 'chat') { + this._chatCreateOrReuse(userId); + return; + } - this.setState({ viewUserId: userId }); - this._setPage(PageTypes.UserView); - this.notifyNewScreen('user/' + userId); - const member = new Matrix.RoomMember(null, userId); - if (member) { + this._setPage(PageTypes.UserView); + this.notifyNewScreen('user/' + userId); + const member = new Matrix.RoomMember(null, userId); dis.dispatch({ action: 'view_user', member: member, }); - } + }); } else if (screen.indexOf('group/') == 0) { const groupId = screen.substring(6); From 2844b574d59124d3957d20da75a08024ef5d2dbd Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 14 Aug 2017 14:41:03 +0100 Subject: [PATCH 3/3] Re-add useful comment --- src/components/structures/MatrixChat.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index a512d60509..8cb111bf82 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1203,6 +1203,8 @@ module.exports = React.createClass({ } else if (screen.indexOf('user/') == 0) { const userId = screen.substring(5); + // Wait for the first sync so that `getRoom` gives us a room object if it's + // in the sync response const waitFor = this.firstSyncPromise ? this.firstSyncPromise.promise : Promise.resolve(); waitFor.then(() => {