From 4f7591965125d7c3289b81ff8bba6ba91512af3f Mon Sep 17 00:00:00 2001 From: Zane Helton Date: Sat, 28 Jun 2025 19:01:49 -0400 Subject: [PATCH] Add OP to message.mentions when replied to The `message.message_reference` stores: 1. `message_id` 2. `channel_id` 3. `guild_id` We use the `message_id` and `channel_id` to `.findOne(...)` Message, and find the author. If the author is the same as OP, we skip (so replying to yourself doesn't add you to the mentions array) otherwise, it adds the author_id to the mentions array. Resolves: #1247 --- src/api/util/handlers/Message.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index 41e55000..0977b1db 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -79,6 +79,7 @@ export async function handleMessage(opts: MessageOptions): Promise { embeds: opts.embeds || [], reactions: opts.reactions || [], type: opts.type ?? 0, + mentions: [], }); if ( @@ -256,12 +257,35 @@ export async function handleMessage(opts: MessageOptions): Promise { } } + if (message.message_reference?.message_id) { + const referencedMessage = await Message.findOne({ + where: { + id: message.message_reference.message_id, + channel_id: message.channel_id, + }, + }); + if ( + referencedMessage && + referencedMessage.author_id !== message.author_id + ) { + message.mentions.push( + User.create({ + id: referencedMessage.author_id, + }), + ); + } + } + // root@Rory - 20/02/2023 - This breaks channel mentions in test client. We're not sure this was used in older clients. /*message.mention_channels = mention_channel_ids.map((x) => Channel.create({ id: x }), );*/ message.mention_roles = mention_role_ids.map((x) => Role.create({ id: x })); - message.mentions = mention_user_ids.map((x) => User.create({ id: x })); + message.mentions = [ + ...message.mentions, + ...mention_user_ids.map((x) => User.create({ id: x })), + ]; + message.mention_everyone = mention_everyone; // TODO: check and put it all in the body