fix room reuse semantics when starting chats
This commit is contained in:
parent
18fc8fc6c4
commit
eadd2a522f
1 changed files with 25 additions and 12 deletions
|
@ -220,18 +220,31 @@ module.exports = React.createClass({
|
||||||
this.props.member.userId,
|
this.props.member.userId,
|
||||||
MatrixClientPeg.get().credentials.userId
|
MatrixClientPeg.get().credentials.userId
|
||||||
];
|
];
|
||||||
var existingRoomId = null;
|
var existingRoomId;
|
||||||
|
|
||||||
|
var currentRoom = MatrixClientPeg.get().getRoom(this.props.member.roomId);
|
||||||
|
var currentMembers = currentRoom.getJoinedMembers();
|
||||||
|
// if we're currently in a 1:1 with this user, start a new chat
|
||||||
|
if (currentMembers.length === 2 &&
|
||||||
|
userIds.indexOf(currentMembers[0].userId) !== -1 &&
|
||||||
|
userIds.indexOf(currentMembers[1].userId) !== -1)
|
||||||
|
{
|
||||||
|
existingRoomId = null;
|
||||||
|
}
|
||||||
|
// otherwise reuse the first private 1:1 we find
|
||||||
|
else {
|
||||||
|
existingRoomId = null;
|
||||||
|
|
||||||
for (var i = 0; i < rooms.length; i++) {
|
for (var 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", '');
|
||||||
|
if (join_rules && join_rules.getContent().join_rule === 'public') continue;
|
||||||
|
|
||||||
var members = rooms[i].getJoinedMembers();
|
var members = rooms[i].getJoinedMembers();
|
||||||
if (members.length === 2) {
|
if (members.length === 2 &&
|
||||||
var hasTargetUsers = true;
|
userIds.indexOf(members[0].userId) !== -1 &&
|
||||||
for (var j = 0; j < members.length; j++) {
|
userIds.indexOf(members[1].userId) !== -1)
|
||||||
if (userIds.indexOf(members[j].userId) === -1) {
|
{
|
||||||
hasTargetUsers = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasTargetUsers) {
|
|
||||||
existingRoomId = rooms[i].roomId;
|
existingRoomId = rooms[i].roomId;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue