From 19387805ac3a95a8f0eaa84406c50767be0f0492 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 12 Jul 2018 19:39:52 +0200 Subject: [PATCH] Don't assume RoomMember has a state event in direct chat detection Instead call the method on the member that takes lazy loading into account --- src/components/structures/RoomView.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 2c322b269d..3a9b3ae748 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -749,21 +749,15 @@ module.exports = React.createClass({ }, _updateDMState() { - const me = this.state.room.getMember(MatrixClientPeg.get().credentials.userId); + const me = this.state.room.getMember(MatrixClientPeg.get().getUserId()); if (!me || me.membership !== "join") { return; } + const roomId = this.state.room.roomId; + const dmInviter = me.getDirectChatInviter(); - // The user may have accepted an invite with is_direct set - if (me.events.member.getPrevContent().membership === "invite" && - me.events.member.getPrevContent().is_direct - ) { - // This is a DM with the sender of the invite event (which we assume - // preceded the join event) - Rooms.setDMRoom( - this.state.room.roomId, - me.events.member.getUnsigned().prev_sender, - ); + if (dmInviter) { + Rooms.setDMRoom(roomId, dmInviter); return; } @@ -777,11 +771,8 @@ module.exports = React.createClass({ // The user may have sent an invite with is_direct sent const other = invitedMembers[0]; - if (other && - other.membership === "invite" && - other.events.member.getContent().is_direct - ) { - Rooms.setDMRoom(this.state.room.roomId, other.userId); + if (other && !!other.getDirectChatInviter()) { + Rooms.setDMRoom(roomId, other.userId); return; } },