summary refs log tree commit diff
path: root/src/api/util
diff options
context:
space:
mode:
authorZane Helton <zane99@me.com>2025-06-28 19:01:49 -0400
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2025-06-29 09:14:58 +1000
commit4f7591965125d7c3289b81ff8bba6ba91512af3f (patch)
tree7bb4692b7cf28349b67c80d223d90cf75ab5a50e /src/api/util
parentPreserve reactions when a message is edited (diff)
downloadserver-ts-4f7591965125d7c3289b81ff8bba6ba91512af3f.tar.xz
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
Diffstat (limited to 'src/api/util')
-rw-r--r--src/api/util/handlers/Message.ts26
1 files changed, 25 insertions, 1 deletions
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<Message> { embeds: opts.embeds || [], reactions: opts.reactions || [], type: opts.type ?? 0, + mentions: [], }); if ( @@ -256,12 +257,35 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { } } + 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