summary refs log tree commit diff
path: root/src/util/entities/Channel.ts
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-07-27 13:50:42 +0200
committerRory& <root@rory.gay>2025-12-17 11:46:31 +0100
commit681efaa2159c875ab8bfaedc61883424e6113fe9 (patch)
treec5f1689543e097d655cc83fdabcd35c91260ef41 /src/util/entities/Channel.ts
parentSetting protos support (diff)
downloadserver-ts-github/emma/schema-updates_wip.tar.xz
Diffstat (limited to 'src/util/entities/Channel.ts')
-rw-r--r--src/util/entities/Channel.ts54
1 files changed, 48 insertions, 6 deletions
diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts

index 8ec801c0..20a35b95 100644 --- a/src/util/entities/Channel.ts +++ b/src/util/entities/Channel.ts
@@ -20,7 +20,17 @@ import { HTTPError } from "lambert-server"; import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm"; import { DmChannelDTO } from "../dtos"; import { ChannelCreateEvent, ChannelRecipientRemoveEvent } from "../interfaces"; -import { InvisibleCharacters, Snowflake, emitEvent, getPermission, trimSpecial, Permissions, BitField } from "../util"; +import { + InvisibleCharacters, + Snowflake, + containsAll, + emitEvent, + getPermission, + trimSpecial, + DiscordApiErrors, + Permissions, + BitField +} from "../util"; import { BaseClass } from "./BaseClass"; import { Guild } from "./Guild"; import { Invite } from "./Invite"; @@ -263,7 +273,7 @@ export class Channel extends BaseClass { if (otherRecipientsUsers.length !== recipients.length) { throw new HTTPError("Recipient/s not found"); } - **/ + **/ const type = recipients.length > 1 ? ChannelType.GROUP_DM : ChannelType.DM; @@ -377,7 +387,6 @@ export class Channel extends BaseClass { static async deleteChannel(channel: Channel) { // TODO Delete attachments from the CDN for messages in the channel - await Channel.delete({ id: channel.id }); if (channel.guild_id) { const guild = await Guild.findOneOrFail({ @@ -385,9 +394,42 @@ export class Channel extends BaseClass { select: { channel_ordering: true }, }); - const updatedOrdering = guild.channel_ordering.filter((id) => id != channel.id); - await Guild.update({ id: channel.guild_id }, { channel_ordering: updatedOrdering }); - } + if (guild.features.includes("COMMUNITY")) { + if ( + [ + guild.afk_channel_id, + guild.system_channel_id, + guild.rules_channel_id, + guild.public_updates_channel_id, + ].includes(channel.id) + ) { + throw DiscordApiErrors.CANNOT_DELETE_COMMUNITY_REQUIRED_CHANNEL; + } + } + else { + if (guild.afk_channel_id === channel.id) { + guild.afk_channel_id = null; + } + if (guild.system_channel_id === channel.id) { + guild.system_channel_id = null; + } + if (guild.rules_channel_id === channel.id) { + guild.rules_channel_id = null; + } + if (guild.public_updates_channel_id === channel.id) { + guild.public_updates_channel_id = null; + } + } + + await Channel.delete({ id: channel.id }); + + const updatedOrdering = guild.channel_ordering.filter( + (id) => id != channel.id, + ); + await Guild.update( + { id: channel.guild_id }, + { channel_ordering: updatedOrdering }, + ); } static async calculatePosition(channel_id: string, guild_id: string, guild?: Guild) {