Skip to content

Commit

Permalink
Merge pull request #1185 from CyberL1/feat/message-pinned-message
Browse files Browse the repository at this point in the history
feat: message pinned message
  • Loading branch information
Puyodead1 authored Aug 18, 2024
2 parents 20637ff + 39e3b5a commit 1b9d755
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/api/routes/channels/#channel_id/pins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import {
DiscordApiErrors,
emitEvent,
Message,
MessageCreateEvent,
MessageUpdateEvent,
User,
} from "@spacebar/util";
import { Request, Response, Router } from "express";

Expand Down Expand Up @@ -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({
Expand All @@ -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);
Expand Down

0 comments on commit 1b9d755

Please sign in to comment.