diff --git a/src/api/routes/channels/#channel_id/index.ts b/src/api/routes/channels/#channel_id/index.ts
index 12333a7f..e8c6ecfb 100644
--- a/src/api/routes/channels/#channel_id/index.ts
+++ b/src/api/routes/channels/#channel_id/index.ts
@@ -134,7 +134,7 @@ router.patch(
"/",
route({
requestBody: "ChannelModifySchema",
- permission: "MANAGE_CHANNELS",
+ permission: "VIEW_CHANNEL",
responses: {
200: {
body: "Channel",
@@ -148,12 +148,38 @@ router.patch(
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/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index d89d39c6..d7f75d8c 100644
--- a/src/api/routes/channels/#channel_id/messages/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -341,6 +341,7 @@ router.post(
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)) {
|