summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTomatoCake <60300461+DEVTomatoCake@users.noreply.github.com>2024-07-17 12:31:09 +0200
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2024-07-17 20:34:09 +1000
commitd3ece937e6e6e476610fc1d7eae085727d01ec95 (patch)
treef8a1625364c9daad0afbeeca070530acb3026499 /src
parentfeat: badge-icons cdn route (diff)
downloadserver-ts-d3ece937e6e6e476610fc1d7eae085727d01ec95.tar.xz
Make channel ID optional when replying
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/channels/#channel_id/messages/#message_id/index.ts9
-rw-r--r--src/api/util/handlers/Message.ts8
-rw-r--r--src/util/schemas/MessageCreateSchema.ts2
3 files changed, 13 insertions, 6 deletions
diff --git a/src/api/routes/channels/#channel_id/messages/#message_id/index.ts b/src/api/routes/channels/#channel_id/messages/#message_id/index.ts

index c4d2e1e8..211cf997 100644 --- a/src/api/routes/channels/#channel_id/messages/#message_id/index.ts +++ b/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
@@ -1,17 +1,17 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ @@ -91,11 +91,10 @@ router.patch( } } else rights.hasThrow("SELF_EDIT_MESSAGES"); + // @ts-expect-error Something is wrong with message_reference here, TS complains since "channel_id" is optional in MessageCreateSchema const new_message = await handleMessage({ ...message, // TODO: should message_reference be overridable? - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore message_reference: message.message_reference, ...body, author_id: message.author_id, diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts
index 14efa95b..c3658668 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts
@@ -117,6 +117,12 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { const guild = await Guild.findOneOrFail({ where: { id: channel.guild_id }, }); + + if (!opts.message_reference.guild_id) + opts.message_reference.guild_id = channel.guild_id; + if (!opts.message_reference.channel_id) + opts.message_reference.channel_id = opts.channel_id; + if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) { if (opts.message_reference.guild_id !== channel.guild_id) throw new HTTPError( @@ -127,6 +133,8 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { "You can only reference messages from this channel", ); } + + message.message_reference = opts.message_reference; } /** Q: should be checked if the referenced message exists? ANSWER: NO otherwise backfilling won't work **/ diff --git a/src/util/schemas/MessageCreateSchema.ts b/src/util/schemas/MessageCreateSchema.ts
index 495e2ebd..014f6c87 100644 --- a/src/util/schemas/MessageCreateSchema.ts +++ b/src/util/schemas/MessageCreateSchema.ts
@@ -42,7 +42,7 @@ export interface MessageCreateSchema { }; message_reference?: { message_id: string; - channel_id: string; + channel_id?: string; guild_id?: string; fail_if_not_exists?: boolean; };