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() { async openDirectMessage() {
const roomBeingCreated = await this._session.createRoom(RoomType.DirectMessage, undefined, undefined, undefined, [this.userId]); const room = this._session.findDirectMessageForUserId(this.userId);
this.navigation.push("room", roomBeingCreated.localId); 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; 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 */ /** @internal */
createJoinedRoom(roomId, pendingEvents) { createJoinedRoom(roomId, pendingEvents) {
return new Room({ return new Room({

View File

@ -420,6 +420,10 @@ export class BaseRoom extends EventEmitter {
return this._summary.data.membership; return this._summary.data.membership;
} }
isDirectMessageForUserId(userId) {
return this._summary.data.dmUserId === userId;
}
async _loadPowerLevels() { async _loadPowerLevels() {
const txn = await this._storage.readTxn([this._storage.storeNames.roomState]); const txn = await this._storage.readTxn([this._storage.storeNames.roomState]);
const powerLevelsState = await txn.roomState.get(this._roomId, "m.room.power_levels", ""); 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; return this._inviter;
} }
isDirectMessageForUserId(userId) {
return this.isDirectMessage && this._inviter.userId === userId;
}
get isPublic() { get isPublic() {
return this._inviteData.joinRule === "public"; return this._inviteData.joinRule === "public";
} }