summary refs log tree commit diff
path: root/api/src/routes/users/@me
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-13 01:11:03 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-13 01:11:03 +0200
commit07ba78d391ac517225d3afa537d7eb4f7b13c74d (patch)
tree82d127530d0d837ad1fdf2ef7b76eda122257bcc /api/src/routes/users/@me
parent:bug: fix channel events + message send (diff)
downloadserver-07ba78d391ac517225d3afa537d7eb4f7b13c74d.tar.xz
:bug: fix dm #321
Diffstat (limited to 'api/src/routes/users/@me')
-rw-r--r--api/src/routes/users/@me/channels.ts16
1 files changed, 8 insertions, 8 deletions
diff --git a/api/src/routes/users/@me/channels.ts b/api/src/routes/users/@me/channels.ts
index 5515a217..da33f204 100644
--- a/api/src/routes/users/@me/channels.ts
+++ b/api/src/routes/users/@me/channels.ts
@@ -4,11 +4,6 @@ import { HTTPError } from "lambert-server";
 import { route } from "@fosscord/api";
 import { In } from "typeorm";
 
-export interface DmChannelCreateSchema {
-	name?: string;
-	recipients: string[];
-}
-
 const router: Router = Router();
 
 router.get("/", route({}), async (req: Request, res: Response) => {
@@ -17,12 +12,17 @@ router.get("/", route({}), async (req: Request, res: Response) => {
 	res.json(recipients.map((x) => x.channel));
 });
 
+export interface DmChannelCreateSchema {
+	name?: string;
+	recipients: string[];
+}
+
 router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request, res: Response) => {
 	const body = req.body as DmChannelCreateSchema;
 
 	body.recipients = body.recipients.filter((x) => x !== req.user_id).unique();
 
-	const recipients = await User.find({ id: In(body.recipients) });
+	const recipients = await User.find({ where: body.recipients.map((x) => ({ id: x })) });
 
 	if (recipients.length !== body.recipients.length) {
 		throw new HTTPError("Recipient/s not found");
@@ -34,10 +34,10 @@ router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request,
 	const channel = await new Channel({
 		name,
 		type,
-		owner_id: req.user_id,
+		// owner_id only for group dm channels
 		created_at: new Date(),
 		last_message_id: null,
-		recipients: [...body.recipients.map((x) => new Recipient({ id: x })), new Recipient({ id: req.user_id })]
+		recipients: [...body.recipients.map((x) => new Recipient({ user_id: x })), new Recipient({ user_id: req.user_id })]
 	}).save();
 
 	await emitEvent({ event: "CHANNEL_CREATE", data: channel, user_id: req.user_id } as ChannelCreateEvent);