From 61e0258b6f3d76d8abfbccf34ba462c82c23ff35 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 2 Aug 2016 15:55:18 +0100 Subject: [PATCH] Include rooms with 1 person invited If we can't find one with both people joined. --- src/components/views/rooms/MemberInfo.js | 33 +++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js index eed5e953d3..f366f3209e 100644 --- a/src/components/views/rooms/MemberInfo.js +++ b/src/components/views/rooms/MemberInfo.js @@ -95,31 +95,31 @@ module.exports = React.createClass({ }, getExistingOneToOneRoomId: function() { - var self = this; - var rooms = MatrixClientPeg.get().getRooms(); - var userIds = [ + const rooms = MatrixClientPeg.get().getRooms(); + const userIds = [ this.props.member.userId, MatrixClientPeg.get().credentials.userId ]; - var existingRoomId; + let existingRoomId = null; + let invitedRoomId = null; // roomId can be null here because of a hack in MatrixChat.onUserClick where we // abuse this to view users rather than room members. - var currentMembers; + let currentMembers; if (this.props.member.roomId) { - var currentRoom = MatrixClientPeg.get().getRoom(this.props.member.roomId); + const currentRoom = MatrixClientPeg.get().getRoom(this.props.member.roomId); currentMembers = currentRoom.getJoinedMembers(); } // reuse the first private 1:1 we find existingRoomId = null; - for (var i = 0; i < rooms.length; i++) { + for (let i = 0; i < rooms.length; i++) { // don't try to reuse public 1:1 rooms - var join_rules = rooms[i].currentState.getStateEvents("m.room.join_rules", ''); + const join_rules = rooms[i].currentState.getStateEvents("m.room.join_rules", ''); if (join_rules && join_rules.getContent().join_rule === 'public') continue; - var members = rooms[i].getJoinedMembers(); + const members = rooms[i].getJoinedMembers(); if (members.length === 2 && userIds.indexOf(members[0].userId) !== -1 && userIds.indexOf(members[1].userId) !== -1) @@ -127,6 +127,21 @@ module.exports = React.createClass({ existingRoomId = rooms[i].roomId; break; } + + const invited = rooms[i].getMembersWithMembership('invite'); + if (members.length === 1 && + invited.length === 1 && + userIds.indexOf(members[0].userId) !== -1 && + userIds.indexOf(invited[0].userId) !== -1) && + invitedRoomId === null + { + invitedRoomId = rooms[i].roomId; + // keep looking: we'll use this one if there's nothing better + } + } + + if (existingRoomId === null) { + existingRoomId = invitedRoomId; } return existingRoomId;