Skip to content

Commit 6be688d

Browse files
Merge pull request #1121 from DEVTomatoCake/fix-deleting-non-empty-categories-1117
Allow deletion of non-empty categories
2 parents c8a90a4 + aa412e0 commit 6be688d

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/api/routes/channels/#channel_id/index.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
22
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
33
Copyright (C) 2023 Spacebar and Spacebar Contributors
4-
4+
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU Affero General Public License as published
77
by the Free Software Foundation, either version 3 of the License, or
88
(at your option) any later version.
9-
9+
1010
This program is distributed in the hope that it will be useful,
1111
but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
GNU Affero General Public License for more details.
14-
14+
1515
You should have received a copy of the GNU Affero General Public License
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
@@ -90,6 +90,24 @@ router.delete(
9090
} else if (channel.type === ChannelType.GROUP_DM) {
9191
await Channel.removeRecipientFromChannel(channel, req.user_id);
9292
} else {
93+
if (channel.type == ChannelType.GUILD_CATEGORY) {
94+
const channels = await Channel.find({
95+
where: { parent_id: channel_id },
96+
});
97+
for await (const c of channels) {
98+
c.parent_id = null;
99+
100+
await Promise.all([
101+
c.save(),
102+
emitEvent({
103+
event: "CHANNEL_UPDATE",
104+
data: c,
105+
channel_id: c.id,
106+
} as ChannelUpdateEvent),
107+
]);
108+
}
109+
}
110+
93111
await Promise.all([
94112
Channel.delete({ id: channel_id }),
95113
emitEvent({

src/util/entities/Channel.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
22
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
33
Copyright (C) 2023 Spacebar and Spacebar Contributors
4-
4+
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU Affero General Public License as published
77
by the Free Software Foundation, either version 3 of the License, or
88
(at your option) any later version.
9-
9+
1010
This program is distributed in the hope that it will be useful,
1111
but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
GNU Affero General Public License for more details.
14-
14+
1515
You should have received a copy of the GNU Affero General Public License
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
@@ -105,7 +105,7 @@ export class Channel extends BaseClass {
105105

106106
@Column({ nullable: true })
107107
@RelationId((channel: Channel) => channel.parent)
108-
parent_id: string;
108+
parent_id: string | null;
109109

110110
@JoinColumn({ name: "parent_id" })
111111
@ManyToOne(() => Channel)

0 commit comments

Comments
 (0)