summary refs log tree commit diff
path: root/src/routes
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-07 04:00:54 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-07 04:00:54 +0200
commit5540d7a9de1623d63fccc4486b2c0388c9cf7327 (patch)
tree1f3c35fb4681c9e73da23c0a5209b3e86aef7eee /src/routes
parent:bug: fix lean not working with virtuals (diff)
downloadserver-5540d7a9de1623d63fccc4486b2c0388c9cf7327.tar.xz
:bug: fix message route
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/channels/#channel_id/messages/index.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/routes/channels/#channel_id/messages/index.ts b/src/routes/channels/#channel_id/messages/index.ts
index cba1d7f0..99f5fdcd 100644
--- a/src/routes/channels/#channel_id/messages/index.ts
+++ b/src/routes/channels/#channel_id/messages/index.ts
@@ -130,6 +130,7 @@ router.post("/", check(MessageCreateSchema), async (req, res) => {
 	const embeds = [];
 	if (body.embed) embeds.push(body.embed);
 
+	// TODO: check and put all in body in it
 	const message: Message = {
 		id: Snowflake.generate(),
 		channel_id,
@@ -145,9 +146,22 @@ router.post("/", check(MessageCreateSchema), async (req, res) => {
 		reactions: [],
 		type: 0,
 		tts: body.tts,
+		nonce: body.nonce,
 	};
 
-	await new MessageModel(message).save();
+	const doc = new MessageModel(message);
+	await doc.save();
 
-	await emitEvent({ event: "MESSAGE_CREATE", channel_id, data: {} } as MessageCreateEvent);
+	const data = toObject(
+		await MessageModel.populate(doc, [
+			{ path: "author", select: PublicUserProjection },
+			{ path: "mentions", select: PublicUserProjection },
+			{ path: "mention_roles" },
+			{ path: "mention_channels", select: { id: true, guild_id: true, type: true, name: true } },
+		])
+	);
+
+	await emitEvent({ event: "MESSAGE_CREATE", channel_id, data, guild_id: channel.guild_id } as MessageCreateEvent);
+
+	return res.send(data);
 });