mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
WIP for finding DM room
This commit is contained in:
parent
26fa2a5d60
commit
e04463c143
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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({
|
||||
|
@ -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", "");
|
||||
|
@ -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";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user