From 06ae64b7b7f97974a04276129655f1d9e3f1b1c1 Mon Sep 17 00:00:00 2001 From: Seth Falco <seth@falco.fun> Date: Thu, 6 Jul 2023 00:35:40 +0100 Subject: [PATCH] fix: correctly handle multiple room bridges Signed-off-by: Seth Falco <seth@falco.fun> --- src/bot.ts | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 2604cbd..1666f13 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1211,16 +1211,6 @@ export class DiscordBot { const reactionName = reaction.emoji.name; log.verbose(`Got message reaction add event for ${message.id} with ${reactionName}`); - let rooms: string[]; - - try { - rooms = await this.channelSync.GetRoomIdsFromChannel(message.channel); - } catch (err) { - log.verbose(`No bridged rooms to forward reaction to. Reaction Event: ${reaction}`); - MetricPeg.get.requestOutcome(message.id, true, "dropped"); - return; - } - const intent = this.GetIntentFromDiscordMember(user); await intent.ensureRegistered(); this.userActivity.updateUserActivity(intent.userId); @@ -1235,25 +1225,22 @@ export class DiscordBot { } while (storeEvent.Next()) { - const matrixIds = storeEvent.MatrixId.split(";"); - - for (const room of rooms) { - const reactionEventId = await intent.underlyingClient.unstableApis.addReactionToEvent( - room, - matrixIds[0], - reaction.emoji.id ? `:${reactionName}:` : reactionName - ); - - const event = new DbEvent(); - event.MatrixId = `${reactionEventId};${room}`; - event.DiscordId = message.id; - event.ChannelId = message.channel.id; - if (message.guild) { - event.GuildId = message.guild.id; - } + const [ eventId, roomId ] = storeEvent.MatrixId.split(";"); + const reactionEventId = await intent.underlyingClient.unstableApis.addReactionToEvent( + roomId, + eventId, + reaction.emoji.id ? `:${reactionName}:` : reactionName + ); - await this.store.Insert(event); + const event = new DbEvent(); + event.MatrixId = `${reactionEventId};${roomId}`; + event.DiscordId = message.id; + event.ChannelId = message.channel.id; + if (message.guild) { + event.GuildId = message.guild.id; } + + await this.store.Insert(event); } } -- GitLab