From 8f42f29f0746b0c7b7b310aea5c92f39436f0146 Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 15 Jul 2026 01:00:32 +0200 Subject: [PATCH] Fix schema for patch webhook message --- .../#webhook_token/messages/#message_id.ts | 30 +++++++++---------- src/database/entities/User.ts | 17 +++++++++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/api/routes/webhooks/#webhook_id/#webhook_token/messages/#message_id.ts b/src/api/routes/webhooks/#webhook_id/#webhook_token/messages/#message_id.ts index 8d69512aa..578730e44 100644 --- a/src/api/routes/webhooks/#webhook_id/#webhook_token/messages/#message_id.ts +++ b/src/api/routes/webhooks/#webhook_id/#webhook_token/messages/#message_id.ts @@ -22,7 +22,7 @@ import multer from "multer"; import { handleMessage, postHandleMessage, route } from "@spacebar/api/util"; import { Channel, Message, Webhook } from "@spacebar/database"; import { MessageDeleteEvent, MessageUpdateEvent, emitEvent, DiscordApiErrors } from "@spacebar/util"; -import { ChannelType, WebhookExecuteSchema } from "@spacebar/schemas"; +import { ChannelType, PublicMessage, WebhookExecuteSchema } from "@spacebar/schemas"; const router = Router({ mergeParams: true }); // TODO: message content/embed string length limit @@ -54,7 +54,7 @@ router.patch( requestBody: "WebhookExecuteSchema", responses: { 200: { - body: "Message", + body: "PublicMessage", }, 400: { body: "APIErrorResponse", @@ -104,21 +104,21 @@ router.patch( ...new_message.toJSON(), id: new_message.id, type: new_message.type, - channel_id: new_message.channel_id, - member: new_message.member?.toPublicMember(), - author: new_message.author?.toPublicUser(), - attachments: new_message.attachments, + channel_id: new_message.channel_id!, + // member: new_message.member?.toPublicMember(), // TODO: why was this here? this isnt in the Message object lol + author: new_message.author!.toPartialUser(), + attachments: new_message.attachments?.map((x) => x.toJSON()) ?? [], embeds: new_message.embeds, - mentions: new_message.embeds, - mention_roles: new_message.mention_roles, - mention_everyone: new_message.mention_everyone, + mentions: new_message.mentions.map((u) => u.toPartialUser()), + mention_roles: new_message.mention_roles.map((r) => r.id), + mention_everyone: new_message.mention_everyone ?? false, pinned: new_message.pinned, - timestamp: new_message.timestamp, - edited_timestamp: new_message.edited_timestamp, + timestamp: new_message.timestamp.toISOString(), + edited_timestamp: new_message.edited_timestamp?.toISOString() ?? null, // these are not in the Discord.com response - mention_channels: new_message.mention_channels, - }); + mention_channels: new_message.mention_channels.map((x) => x.toJSON()), + } satisfies PublicMessage); }, ); @@ -127,7 +127,7 @@ router.get( route({ responses: { 200: { - body: "Message", + body: "PublicMessage", }, 400: { body: "APIErrorResponse", @@ -149,7 +149,7 @@ router.get( }, }); - return res.json(message); + return res.json(message.toJSON()); }, ); diff --git a/src/database/entities/User.ts b/src/database/entities/User.ts index d352cc794..140fed2a3 100644 --- a/src/database/entities/User.ts +++ b/src/database/entities/User.ts @@ -33,6 +33,7 @@ import { ChannelType, Collectibles, DisplayNameStyle, + PartialUser, PrimaryGuild, PrivateUserProjection, PublicUser, @@ -222,6 +223,22 @@ export class User extends BaseClass { return user as PublicUser; } + toPartialUser(): PartialUser { + return { + id: this.id, + username: this.username, + discriminator: this.discriminator, + global_name: undefined, // TODO when pomelo + avatar: this.avatar ?? null, + avatar_decoration_data: this.avatar_decoration_data, + bot: this.bot, + system: this.system, + banner: this.banner, + accent_color: this.accent_color, + public_flags: this.public_flags, + } satisfies PartialUser; + } + toPrivateUser(extraFields: (keyof User)[] = []) { this.clean_data(); // eslint-disable-next-line @typescript-eslint/no-explicit-any