From d18f6a699a9698f41c14f63f77063b16ac0deb38 Mon Sep 17 00:00:00 2001 From: emerson Date: Mon, 2 May 2022 20:05:07 -0400 Subject: [PATCH] quick fix to alert to any invited rooms --- src/Server.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Server.ts b/src/Server.ts index b4ec5f7..27d4156 100644 --- a/src/Server.ts +++ b/src/Server.ts @@ -9,6 +9,7 @@ export class Server { public name: string public apiCall: Axios public channels: Map + public invitedChannels: Set public roomIdToChannel: Map public directRooms: Map private syncLocks: Set @@ -33,6 +34,7 @@ export class Server { headers: {"Authorization": `Bearer ${this.config.accessToken}`} }) this.channels = new Map(); + this.invitedChannels = new Set(); this.roomIdToChannel = new Map(); this.directRooms = new Map(); this.syncLocks = new Set(); @@ -74,13 +76,20 @@ export class Server { const data = response.data; this.nextBatch = data.next_batch; const rooms = data.rooms; - if (rooms && rooms['join']) { - for (const roomId of Object.keys(rooms.join)) { - const targetChannel = this.getOrCreateIRCChannel(roomId); - rooms.join[roomId].timeline.events.forEach((nextEvent: any) => { - if (targetChannel.isSynced()) - this.routeMatrixEvent(nextEvent, targetChannel); - }); + if (rooms) { + if (rooms['join']) { + for (const roomId of Object.keys(rooms.join)) { + const targetChannel = this.getOrCreateIRCChannel(roomId); + rooms.join[roomId].timeline.events.forEach((nextEvent: any) => { + if (targetChannel.isSynced()) + this.routeMatrixEvent(nextEvent, targetChannel); + }); + } + } + if (rooms['invite']) { + for (const roomId of Object.keys(rooms.invite)) { + this.invitedChannels.add(roomId); + } } } this.isSyncing = false; @@ -123,6 +132,7 @@ export class Server { finishChannelSync(targetChannel: Channel) { this.syncLocks.delete(targetChannel); this.channels.delete(targetChannel.roomId); + this.invitedChannels.delete(targetChannel.roomId); this.channels.set(targetChannel.name, targetChannel); this.roomIdToChannel.set(targetChannel.roomId, targetChannel); this.clients.forEach(c => this.joinNewIRCClient(c, targetChannel)); @@ -195,6 +205,7 @@ export class Server { for (const channel of this.channels.values()) { this.joinNewIRCClient(client, channel); } + this.invitedChannels.forEach(roomId => this.sendToAll(this.name, "INVITE", [this.ourMatrixUser.nick, roomId], new Map())); } }