summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2024-08-18 10:49:47 -0400
committerGitHub <noreply@github.com>2024-08-18 10:49:47 -0400
commit1b9d75524ac566bd9ca94c53ba3f766e4df8a37f (patch)
tree4bcc2d86f69e4dbf77262b5bb81e009e53204fb0 /src/api
parentMerge pull request #1186 from DEVTomatoCake/fix/consistent-widget-disabled-error (diff)
parentfeat: emit `MESSAGE_CREATE` (diff)
downloadserver-ts-1b9d75524ac566bd9ca94c53ba3f766e4df8a37f.tar.xz
Merge pull request #1185 from CyberL1/feat/message-pinned-message
feat: message pinned message
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/channels/#channel_id/pins.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/api/routes/channels/#channel_id/pins.ts b/src/api/routes/channels/#channel_id/pins.ts

index 1e1da018..d43db6ec 100644 --- a/src/api/routes/channels/#channel_id/pins.ts +++ b/src/api/routes/channels/#channel_id/pins.ts
@@ -23,7 +23,9 @@ import { DiscordApiErrors, emitEvent, Message, + MessageCreateEvent, MessageUpdateEvent, + User, } from "@spacebar/util"; import { Request, Response, Router } from "express"; @@ -61,6 +63,30 @@ router.put( message.pinned = true; + const author = await User.getPublicUser(req.user_id); + + const systemPinMessage = Message.create({ + timestamp: new Date(), + type: 6, + guild_id: message.guild_id, + channel_id: message.channel_id, + author, + message_reference: { + message_id: message.id, + channel_id: message.channel_id, + guild_id: message.guild_id, + }, + reactions: [], + attachments: [], + embeds: [], + sticker_items: [], + edited_timestamp: undefined, + mentions: [], + mention_channels: [], + mention_roles: [], + mention_everyone: false, + }); + await Promise.all([ message.save(), emitEvent({ @@ -77,6 +103,12 @@ router.put( last_pin_timestamp: undefined, }, } as ChannelPinsUpdateEvent), + systemPinMessage.save(), + emitEvent({ + event: "MESSAGE_CREATE", + channel_id: message.channel_id, + data: systemPinMessage, + } as MessageCreateEvent), ]); res.sendStatus(204);