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;
|
||||||
for (var i = 0; i < rooms.length; i++) {
|
|
||||||
var members = rooms[i].getJoinedMembers();
|
var currentRoom = MatrixClientPeg.get().getRoom(this.props.member.roomId);
|
||||||
if (members.length === 2) {
|
var currentMembers = currentRoom.getJoinedMembers();
|
||||||
var hasTargetUsers = true;
|
// if we're currently in a 1:1 with this user, start a new chat
|
||||||
for (var j = 0; j < members.length; j++) {
|
if (currentMembers.length === 2 &&
|
||||||
if (userIds.indexOf(members[j].userId) === -1) {
|
userIds.indexOf(currentMembers[0].userId) !== -1 &&
|
||||||
hasTargetUsers = false;
|
userIds.indexOf(currentMembers[1].userId) !== -1)
|
||||||
break;
|
{
|
||||||
}
|
existingRoomId = null;
|
||||||
}
|
}
|
||||||
if (hasTargetUsers) {
|
// otherwise reuse the first private 1:1 we find
|
||||||
|
else {
|
||||||
|
existingRoomId = null;
|
||||||
|
|
||||||
|
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();
|
||||||
|
if (members.length === 2 &&
|
||||||
|
userIds.indexOf(members[0].userId) !== -1 &&
|
||||||
|
userIds.indexOf(members[1].userId) !== -1)
|
||||||
|
{
|
||||||
existingRoomId = rooms[i].roomId;
|
existingRoomId = rooms[i].roomId;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue