Skip to content
Snippets Groups Projects
Unverified Commit 47c76c85 authored by R Midhun Suresh's avatar R Midhun Suresh Committed by GitHub
Browse files

Merge pull request #61 from vector-im/use-previous-room

Use better logic for finding previously created room
parents 9b96be6d 236b365f
No related branches found
No related tags found
No related merge requests found
......@@ -37,9 +37,9 @@ export class ChatterboxViewModel extends ViewModel {
private async createRoomWithUserSpecifiedInConfig() {
const userId = this._options.config["invite_user"];
let room = this._session.findDirectMessageForUserId(userId);
let room = await this.findPreviouslyCreatedRoom();
if (room) {
// we already have a DM with this user
// we already have a room with this user
return room;
}
const roomBeingCreated = this._session.createRoom({
......@@ -56,6 +56,7 @@ export class ChatterboxViewModel extends ViewModel {
await roomStatusObservable.waitFor(status => status === (RoomStatus.BeingCreated | RoomStatus.Replaced)).promise;
const roomId = roomBeingCreated.roomId;
await this.platform.settingsStorage.setString("created-room-id", roomId);
await this.platform.settingsStorage.setString("invite-user", userId);
room = this._session.rooms.get(roomId);
return room;
}
......@@ -89,6 +90,16 @@ export class ChatterboxViewModel extends ViewModel {
this._session.rooms.subscribe(subscription);
return promise;
}
private async findPreviouslyCreatedRoom(): Promise<string | null> {
const createdRoomId = await this.platform.settingsStorage.getString("created-room-id");
const lastKnownInviteUserId = await this.platform.settingsStorage.getString("invite-user");
const currentInviteUserId = this._options.config["invite_user"];
if (createdRoomId && lastKnownInviteUserId === currentInviteUserId) {
return this._session.rooms.get(createdRoomId);
}
return null;
}
minimize() {
(window as any).sendMinimizeToParent();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment