summary refs log tree commit diff
path: root/api/src/routes
diff options
context:
space:
mode:
authorAlTech98 <altech123159@gmail.com>2021-09-18 18:36:29 +0200
committerAlTech98 <altech123159@gmail.com>2021-09-18 18:36:29 +0200
commitceb770fb5b6648c18d66d6997c8916ed60b8c192 (patch)
tree1995cbe4ec0dfe53860d8520b1de39ed4e02e0d6 /api/src/routes
parentFix gateway not listening for new channels events (diff)
downloadserver-ceb770fb5b6648c18d66d6997c8916ed60b8c192.tar.xz
Removed ChannelService, more fixes
Diffstat (limited to 'api/src/routes')
-rw-r--r--api/src/routes/channels/#channel_id/index.ts4
-rw-r--r--api/src/routes/channels/#channel_id/messages/index.ts6
-rw-r--r--api/src/routes/channels/#channel_id/recipients.ts6
-rw-r--r--api/src/routes/users/@me/channels.ts4
4 files changed, 10 insertions, 10 deletions
diff --git a/api/src/routes/channels/#channel_id/index.ts b/api/src/routes/channels/#channel_id/index.ts
index 70dd3994..3f434f5e 100644
--- a/api/src/routes/channels/#channel_id/index.ts
+++ b/api/src/routes/channels/#channel_id/index.ts
@@ -1,4 +1,4 @@
-import { Channel, ChannelDeleteEvent, ChannelPermissionOverwriteType, ChannelService, ChannelType, ChannelUpdateEvent, emitEvent, Recipient } from "@fosscord/util";
+import { Channel, ChannelDeleteEvent, ChannelPermissionOverwriteType, ChannelType, ChannelUpdateEvent, emitEvent, Recipient } from "@fosscord/util";
 import { Request, Response, Router } from "express";
 import { handleFile, route } from "@fosscord/api";
 
@@ -28,7 +28,7 @@ router.delete("/", route({ permission: "MANAGE_CHANNELS" }), async (req: Request
 		]);
 
 	} else if (channel.type === ChannelType.GROUP_DM) {
-		await ChannelService.removeRecipientFromChannel(channel, req.user_id)
+		await Channel.removeRecipientFromChannel(channel, req.user_id)
 	} else {
 		//TODO messages in this channel should be deleted before deleting the channel
 		await Promise.all([
diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts
index bb610a6a..cde14164 100644
--- a/api/src/routes/channels/#channel_id/messages/index.ts
+++ b/api/src/routes/channels/#channel_id/messages/index.ts
@@ -1,5 +1,5 @@
 import { Router, Response, Request } from "express";
-import { Attachment, Channel, ChannelType, DmChannelDTO, Embed, emitEvent, getPermission, Message, MessageCreateEvent } from "@fosscord/util";
+import { Attachment, Channel, ChannelType, DmChannelDTO, Embed, emitEvent, getPermission, Message, MessageCreateEvent, Recipient } from "@fosscord/util";
 import { HTTPError } from "lambert-server";
 import { handleMessage, postHandleMessage, route } from "@fosscord/api";
 import multer from "multer";
@@ -150,7 +150,6 @@ router.post(
 				return res.status(400).json(error);
 			}
 		}
-		//TODO querying the DB at every message post should be avoided, caching maybe?
 		const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients", "recipients.user"] })
 
 		const embeds = [];
@@ -184,7 +183,8 @@ router.post(
 				}
 			}
 
-			await Promise.all(channel.recipients!.map(async r => {
+			//Only one recipients should be closed here, since in group DMs the recipient is deleted not closed
+			await Promise.all(channel.recipients!.filter(r => r.closed).map(async r => {
 				r.closed = false;
 				return await r.save()
 			}));
diff --git a/api/src/routes/channels/#channel_id/recipients.ts b/api/src/routes/channels/#channel_id/recipients.ts
index d88b38f3..c7beeee8 100644
--- a/api/src/routes/channels/#channel_id/recipients.ts
+++ b/api/src/routes/channels/#channel_id/recipients.ts
@@ -1,5 +1,5 @@
 import { Request, Response, Router } from "express";
-import { Channel, ChannelRecipientAddEvent, ChannelService, ChannelType, DiscordApiErrors, DmChannelDTO, emitEvent, PublicUserProjection, Recipient, User } from "@fosscord/util";
+import { Channel, ChannelRecipientAddEvent, ChannelType, DiscordApiErrors, DmChannelDTO, emitEvent, PublicUserProjection, Recipient, User } from "@fosscord/util";
 
 const router: Router = Router();
 
@@ -13,7 +13,7 @@ router.put("/:user_id", async (req: Request, res: Response) => {
 			user_id
 		].unique()
 
-		const new_channel = await ChannelService.createDMChannel(recipients, req.user_id)
+		const new_channel = await Channel.createDMChannel(recipients, req.user_id)
 		return res.status(201).json(new_channel);
 	} else {
 		if (channel.recipients!.map(r => r.user_id).includes(user_id)) {
@@ -49,7 +49,7 @@ router.delete("/:user_id", async (req: Request, res: Response) => {
 		throw DiscordApiErrors.INVALID_RECIPIENT //TODO is this the right error?
 	}
 
-	await ChannelService.removeRecipientFromChannel(channel, user_id)
+	await Channel.removeRecipientFromChannel(channel, user_id)
 
 	return res.sendStatus(204);
 });
diff --git a/api/src/routes/users/@me/channels.ts b/api/src/routes/users/@me/channels.ts
index 873ff245..b5782eca 100644
--- a/api/src/routes/users/@me/channels.ts
+++ b/api/src/routes/users/@me/channels.ts
@@ -1,5 +1,5 @@
 import { Request, Response, Router } from "express";
-import { Recipient, ChannelService, DmChannelDTO } from "@fosscord/util";
+import { Recipient, DmChannelDTO, Channel } from "@fosscord/util";
 import { route } from "@fosscord/api";
 
 const router: Router = Router();
@@ -16,7 +16,7 @@ export interface DmChannelCreateSchema {
 
 router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request, res: Response) => {
 	const body = req.body as DmChannelCreateSchema;
-	res.json(await ChannelService.createDMChannel(body.recipients, req.user_id, body.name));
+	res.json(await Channel.createDMChannel(body.recipients, req.user_id, body.name));
 });
 
 export default router;