WIP for finding DM room

This commit is contained in:
Bruno Windels 2022-02-07 18:58:53 +01:00
parent 26fa2a5d60
commit e04463c143
4 changed files with 29 additions and 2 deletions

View file

@ -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);
}
}

View file

@ -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({

View file

@ -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", "");

View file

@ -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";
}