Skip to content
Snippets Groups Projects
Commit 4c22b845 authored by RMidhunSuresh's avatar RMidhunSuresh
Browse files

Return existing dm rather than creating new dm

parent 2dc97755
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,12 @@ export class ChatterboxViewModel extends ViewModel { ...@@ -36,6 +36,12 @@ export class ChatterboxViewModel extends ViewModel {
} }
private async createRoomWithUserSpecifiedInConfig() { private async createRoomWithUserSpecifiedInConfig() {
const userId = this._options.config["invite_user"];
let room = this._session.findDirectMessageForUserId(userId);
if (room) {
// we already have a DM with this user
return room;
}
const roomBeingCreated = this._session.createRoom({ const roomBeingCreated = this._session.createRoom({
type: 1, type: 1,
name: this._name ?? undefined, name: this._name ?? undefined,
...@@ -44,11 +50,11 @@ export class ChatterboxViewModel extends ViewModel { ...@@ -44,11 +50,11 @@ export class ChatterboxViewModel extends ViewModel {
isFederationDisabled: false, isFederationDisabled: false,
alias: undefined, alias: undefined,
avatar: undefined, avatar: undefined,
invites: [this._options.config["invite_user"]], invites: [userId],
}); });
await this._waitForRoomCreation(roomBeingCreated); await this._waitForRoomCreation(roomBeingCreated);
const roomId = roomBeingCreated.roomId; const roomId = roomBeingCreated.roomId;
let room = this._session.rooms.get(roomId); room = this._session.rooms.get(roomId);
if (!room) { if (!room) {
await this._waitForRoomFromSync(roomId); await this._waitForRoomFromSync(roomId);
room = this._session.rooms.get(roomId); room = this._session.rooms.get(roomId);
......
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