Skip to content

Commit

Permalink
fix: correctly handle multiple room bridges
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Jul 5, 2023
1 parent 20f9048 commit a13f247
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,16 +1197,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);
Expand All @@ -1221,25 +1211,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);
}
}

Expand Down

0 comments on commit a13f247

Please sign in to comment.