mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-27 22:34:11 +00:00
thread improvements
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -30,6 +30,7 @@ export interface ChannelModifySchema {
|
||||
user_limit?: number;
|
||||
rate_limit_per_user?: number;
|
||||
position?: number;
|
||||
invitable?: boolean;
|
||||
permission_overwrites?: {
|
||||
id: string;
|
||||
type: ChannelPermissionOverwriteType;
|
||||
|
||||
Reference in New Issue
Block a user