diff --git "a/src/api/routes/channels/\043channel_id/index.ts" "b/src/api/routes/channels/\043channel_id/index.ts" index 12333a7..e8c6ecf 100644 --- "a/src/api/routes/channels/\043channel_id/index.ts" +++ "b/src/api/routes/channels/\043channel_id/index.ts" @@ -134,7 +134,7 @@ "/", route({ requestBody: "ChannelModifySchema", - permission: "MANAGE_CHANNELS", + permission: "VIEW_CHANNEL", responses: { 200: { body: "Channel", @@ -148,12 +148,38 @@ async (req: Request, res: Response) => { const payload = req.body as ChannelModifySchema; const { channel_id } = req.params as { [key: string]: string }; - if (payload.icon) payload.icon = await handleFile(`/channel-icons/${channel_id}`, payload.icon); - const channel = await Channel.findOneOrFail({ where: { id: channel_id }, }); + + if (channel.isThread()) { + if (channel.owner_id !== req.user.id) { + req.permission!.hasThrow("MANAGE_THREADS"); + } + if (payload.permission_overwrites) { + //TODO better error maybe? + throw new Error("You can't change permission overwrites for threads"); + } + } else { + req.permission!.hasThrow("MANAGE_CHANNELS"); + } + + if (payload.icon) payload.icon = await handleFile(`/channel-icons/${channel_id}`, payload.icon); + channel.assign(payload); + if (channel.thread_metadata) { + if (payload.archived !== undefined) { + channel.thread_metadata.archived = payload.archived; + channel.thread_metadata.archive_timestamp = new Date().toISOString(); + } + if (payload.locked !== undefined) channel.thread_metadata.locked = payload.locked; + if (payload.auto_archive_duration !== undefined) channel.thread_metadata.auto_archive_duration = payload.auto_archive_duration; + if (payload.invitable !== undefined) channel.thread_metadata.invitable = payload.invitable; + if (payload.locked !== undefined) { + req.permission!.hasThrow("MANAGE_THREADS"); + channel.thread_metadata.locked = payload.locked; + } + } await Promise.all([ channel.save(), diff --git "a/src/api/routes/channels/\043channel_id/messages/index.ts" "b/src/api/routes/channels/\043channel_id/messages/index.ts" index d89d39c..d7f75d8 100644 --- "a/src/api/routes/channels/\043channel_id/messages/index.ts" +++ "b/src/api/routes/channels/\043channel_id/messages/index.ts" @@ -341,6 +341,7 @@ where: { id: channel_id }, relations: { recipients: { user: true } }, }); + if (channel.thread_metadata?.locked) throw DiscordApiErrors.THREAD_IS_LOCKED; if (channel.isThread()) { req.permission!.hasThrow("SEND_MESSAGES_IN_THREADS"); if (channel.recipients && !channel.recipients.find(({ id }) => id === req.user_id)) { diff --git a/src/schemas/uncategorised/ChannelModifySchema.ts b/src/schemas/uncategorised/ChannelModifySchema.ts index 6cfe340..77836ca 100644 --- a/src/schemas/uncategorised/ChannelModifySchema.ts +++ b/src/schemas/uncategorised/ChannelModifySchema.ts @@ -30,6 +30,7 @@ user_limit?: number; rate_limit_per_user?: number; position?: number; + invitable?: boolean; permission_overwrites?: { id: string; type: ChannelPermissionOverwriteType;