1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-11-07 10:46:24 +03:00

Update createRoom to support creating DM rooms

* Make ChatInviteDialog and MemberInfo createRoom use it
* Fix bug in setDMRoom
This commit is contained in:
David Baker
2016-09-09 19:25:00 +01:00
parent 8160613e01
commit 96fabe09d2
4 changed files with 38 additions and 23 deletions

View File

@@ -93,14 +93,12 @@ export function setDMRoom(roomId, userId) {
if (mDirectEvent !== undefined) dmRoomMap = mDirectEvent.getContent();
// remove it from the lists of any others users
// (it can only be a DM room for one person)
for (const thisUserId of Object.keys(dmRoomMap)) {
const roomList = dmRoomMap[thisUserId];
if (thisUserId == userId) {
if (roomList.indexOf(roomId) == -1) {
roomList.push(roomId);
}
} else {
if (thisUserId != userId) {
const indexOfRoom = roomList.indexOf(roomId);
if (indexOfRoom > -1) {
roomList.splice(indexOfRoom, 1);
@@ -108,6 +106,14 @@ export function setDMRoom(roomId, userId) {
}
}
// now add it, if it's not already there
const roomList = dmRoomMap[userId] || [];
if (roomList.indexOf(roomId) == -1) {
roomList.push(roomId);
}
dmRoomMap[userId] = roomList;
return MatrixClientPeg.get().setAccountData('m.direct', dmRoomMap);
}