Merge pull request #382 from fosscord/auto-delete-relations

Auto delete relations
This commit is contained in:
Flam3rboy
2021-09-20 21:27:08 +02:00
committed by GitHub
29 changed files with 363 additions and 171 deletions
+14 -6
View File
@@ -1,6 +1,15 @@
import { Channel, ChannelDeleteEvent, ChannelPermissionOverwriteType, ChannelType, ChannelUpdateEvent, emitEvent, Recipient } from "@fosscord/util";
import {
Channel,
ChannelDeleteEvent,
ChannelPermissionOverwriteType,
ChannelType,
ChannelUpdateEvent,
emitEvent,
Recipient,
handleFile
} from "@fosscord/util";
import { Request, Response, Router } from "express";
import { handleFile, route } from "@fosscord/api";
import { route } from "@fosscord/api";
const router: Router = Router();
// TODO: delete channel
@@ -20,15 +29,14 @@ router.delete("/", route({ permission: "MANAGE_CHANNELS" }), async (req: Request
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients"] });
if (channel.type === ChannelType.DM) {
const recipient = await Recipient.findOneOrFail({ where: { channel_id: channel_id, user_id: req.user_id } })
recipient.closed = true
const recipient = await Recipient.findOneOrFail({ where: { channel_id: channel_id, user_id: req.user_id } });
recipient.closed = true;
await Promise.all([
recipient.save(),
emitEvent({ event: "CHANNEL_DELETE", data: channel, user_id: req.user_id } as ChannelDeleteEvent)
]);
} else if (channel.type === ChannelType.GROUP_DM) {
await Channel.removeRecipientFromChannel(channel, req.user_id)
await Channel.removeRecipientFromChannel(channel, req.user_id);
} else {
await Promise.all([
Channel.delete({ id: channel_id }),
@@ -3,7 +3,6 @@ import { Router, Response, Request } from "express";
import { route } from "@fosscord/api";
import { handleMessage, postHandleMessage } from "@fosscord/api";
import { MessageCreateSchema } from "../index";
import { deleteMessageAttachments } from "@fosscord/api/util/Attachments";
const router = Router();
// TODO: message content/embed string length limit
@@ -34,7 +33,6 @@ router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGE
});
await Promise.all([
await deleteMessageAttachments(message_id, new_message.attachments), //This delete all the attachments not in the array
new_message!.save(),
await emitEvent({
event: "MESSAGE_UPDATE",
@@ -60,7 +58,6 @@ router.delete("/", route({}), async (req: Request, res: Response) => {
permission.hasThrow("MANAGE_MESSAGES");
}
await deleteMessageAttachments(message_id);
await Message.delete({ id: message_id });
await emitEvent({