diff --git a/package-lock.json b/package-lock.json
index 8509e268..6b29af59 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -554,7 +554,8 @@
"bson": "^1.1.4",
"denque": "^1.4.1",
"optional-require": "^1.0.2",
- "safe-buffer": "^5.1.2"
+ "safe-buffer": "^5.1.2",
+ "saslprep": "^1.0.0"
},
"engines": {
"node": ">=4"
@@ -970,6 +971,7 @@
"jest-resolve": "^26.6.2",
"jest-util": "^26.6.2",
"jest-worker": "^26.6.2",
+ "node-notifier": "^8.0.0",
"slash": "^3.0.0",
"source-map": "^0.6.0",
"string-length": "^4.0.1",
@@ -2812,6 +2814,7 @@
"dependencies": {
"anymatch": "~3.1.1",
"braces": "~3.0.2",
+ "fsevents": "~2.3.1",
"glob-parent": "~5.1.0",
"is-binary-path": "~2.1.0",
"is-glob": "~4.0.1",
@@ -6086,6 +6089,7 @@
"@types/node": "*",
"anymatch": "^3.0.3",
"fb-watchman": "^2.0.0",
+ "fsevents": "^2.1.2",
"graceful-fs": "^4.2.4",
"jest-regex-util": "^26.0.0",
"jest-serializer": "^26.6.2",
@@ -8211,7 +8215,8 @@
"bson": "^1.1.4",
"denque": "^1.4.1",
"require_optional": "^1.0.1",
- "safe-buffer": "^5.1.2"
+ "safe-buffer": "^5.1.2",
+ "saslprep": "^1.0.0"
},
"engines": {
"node": ">=4"
diff --git a/src/routes/channels/#channel_id/index.ts b/src/routes/channels/#channel_id/index.ts
index 730c1a67..d1c64267 100644
--- a/src/routes/channels/#channel_id/index.ts
+++ b/src/routes/channels/#channel_id/index.ts
@@ -1,4 +1,4 @@
-import { ChannelDeleteEvent, ChannelModel, ChannelUpdateEvent, getPermission, toObject } from "@fosscord/server-util";
+import { ChannelDeleteEvent, ChannelModel, ChannelUpdateEvent, getPermission, GuildUpdateEvent, toObject } from "@fosscord/server-util";
import { Router } from "express";
import { HTTPError } from "lambert-server";
import { ChannelModifySchema } from "../../../schema/Channel";
@@ -11,17 +11,21 @@ const router: Router = Router();
router.delete("/", async (req, res) => {
const { channel_id } = req.params
- const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true, type: true, permission_overwrites: true }).exec();
+ const channel = await ChannelModel.findOne({ id: channel_id }).exec();
if (!channel) throw new HTTPError("Channel not found", 404);
- const permission = await getPermission(req.user_id, channel.guild_id)
- permission.hasThrow("MANAGE_CHANNELS")
+ if (channel.guild_id) {
- // TODO Channel Update Gateway event will fire for each of them
+ const permission = await getPermission(req.user_id, channel.guild_id)
+ permission.hasThrow("MANAGE_CHANNELS")
+ }
+ // TODO Channel Update Gateway event will fire for each of them
await ChannelModel.deleteOne({ id: channel_id })
// TODO: Dm channel "close" not delete
+
+ await emitEvent({ event: "CHANNEL_DELETE", data: channel, guild_id: channel_id, channel_id} as ChannelDeleteEvent);
const data = toObject(channel);
//TODO: Reload channel list if request successful
diff --git a/src/routes/guilds/#guild_id/channels.ts b/src/routes/guilds/#guild_id/channels.ts
index d42ba481..19d466f3 100644
--- a/src/routes/guilds/#guild_id/channels.ts
+++ b/src/routes/guilds/#guild_id/channels.ts
@@ -31,8 +31,9 @@ router.post("/", check(ChannelModifySchema), async (req, res) => {
}
if (body.parent_id) {
- const exists = ChannelModel.findOne({ channel_id: body.parent_id }).exec();
+ const exists = await ChannelModel.findOne({ id: body.parent_id }, {guild_id:true}).exec();
if (!exists) throw new HTTPError("Parent id channel doesn't exist", 400);
+ if (exists.guild_id !== guild_id) throw new HTTPError("The category channel needs to be in the guild")
}
const guild = await GuildModel.findOne({ id: guild_id }, { id: true }).exec();
|