From d5b23e9e0eed0e4095299b0e994c8cfac0aa511e Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 6 Sep 2016 17:43:39 +0100 Subject: [PATCH] Save guessed DM rooms to account data Also bugfix --- src/components/views/rooms/RoomList.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index 6ce85af82b..5067cdc92e 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -265,12 +265,27 @@ module.exports = React.createClass({ for (const room of oldRecents) { const me = room.getMember(MatrixClientPeg.get().credentials.userId); - if (!me || MatrixTools.looksLikeDirectMessageRoom(room, me)) { - s.lists["im.vector.fake.recent"].push(room); - } else { + if (me && MatrixTools.looksLikeDirectMessageRoom(room, me)) { s.lists["im.vector.fake.direct"].push(room); + } else { + s.lists["im.vector.fake.recent"].push(room); } } + + // save these new guessed DM rooms into the account data + const newMDirectEvent = {}; + for (const room of s.lists["im.vector.fake.direct"]) { + const me = room.getMember(MatrixClientPeg.get().credentials.userId); + const otherPerson = MatrixTools.getOnlyOtherMember(room, me); + if (!otherPerson) continue; + + const roomList = newMDirectEvent[otherPerson.userId] || []; + roomList.push(room.roomId); + newMDirectEvent[otherPerson.userId] = roomList; + } + + // if this fails, fine, we'll just do the same thing next time we get the room lists + MatrixClientPeg.get().setAccountData('m.direct', newMDirectEvent).done(); } //console.log("calculated new roomLists; im.vector.fake.recent = " + s.lists["im.vector.fake.recent"]);