diff --git a/src/domain/session/rightpanel/MemberDetailsViewModel.js b/src/domain/session/rightpanel/MemberDetailsViewModel.js index b0573bfa..f56aac9a 100644 --- a/src/domain/session/rightpanel/MemberDetailsViewModel.js +++ b/src/domain/session/rightpanel/MemberDetailsViewModel.js @@ -83,7 +83,13 @@ export class MemberDetailsViewModel extends ViewModel { } async openDirectMessage() { - const roomBeingCreated = await this._session.createRoom(RoomType.DirectMessage, undefined, undefined, undefined, [this.userId]); - this.navigation.push("room", roomBeingCreated.localId); + const room = this._session.findDirectMessageForUserId(this.userId); + let roomId = room?.id; + if (!roomId) { + const roomBeingCreated = await this._session.createRoom( + RoomType.DirectMessage, undefined, undefined, undefined, [this.userId], {loadProfiles: true}); + roomId = roomBeingCreated.localId; + } + this.navigation.push("room", roomId); } } diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 13901e6c..45cd9b19 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -537,6 +537,19 @@ export class Session { return this._rooms; } + findDirectMessageForUserId(userId) { + for (const [,room] of this._rooms) { + if (room.isDirectMessageForUserId(userId)) { + return room; + } + } + for (const [,invite] of this._invites) { + if (invite.isDirectMessageForUserId(userId)) { + return invite; + } + } + } + /** @internal */ createJoinedRoom(roomId, pendingEvents) { return new Room({ diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index ecd2d860..446c22d1 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -420,6 +420,10 @@ export class BaseRoom extends EventEmitter { return this._summary.data.membership; } + isDirectMessageForUserId(userId) { + return this._summary.data.dmUserId === userId; + } + async _loadPowerLevels() { const txn = await this._storage.readTxn([this._storage.storeNames.roomState]); const powerLevelsState = await txn.roomState.get(this._roomId, "m.room.power_levels", ""); diff --git a/src/matrix/room/Invite.js b/src/matrix/room/Invite.js index da721c77..18bb7b8d 100644 --- a/src/matrix/room/Invite.js +++ b/src/matrix/room/Invite.js @@ -73,6 +73,10 @@ export class Invite extends EventEmitter { return this._inviter; } + isDirectMessageForUserId(userId) { + return this.isDirectMessage && this._inviter.userId === userId; + } + get isPublic() { return this._inviteData.joinRule === "public"; }