summary refs log tree commit diff
path: root/api/src/util/handlers/Message.ts
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-08 22:49:16 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-09 23:28:27 +0200
commit26293f37a1f7af131507c0bdd490d2e07f1a9ba7 (patch)
tree3fdaa7b65f1b66069d08d06143a43c9908395a09 /api/src/util/handlers/Message.ts
parentClean up BaseClient assign call (diff)
downloadserver-26293f37a1f7af131507c0bdd490d2e07f1a9ba7.tar.xz
Use deep merge everywhere
Diffstat (limited to 'api/src/util/handlers/Message.ts')
-rw-r--r--api/src/util/handlers/Message.ts9
1 files changed, 5 insertions, 4 deletions
diff --git a/api/src/util/handlers/Message.ts b/api/src/util/handlers/Message.ts
index 34fb3d05..0f584c56 100644
--- a/api/src/util/handlers/Message.ts
+++ b/api/src/util/handlers/Message.ts
@@ -26,6 +26,7 @@ import { HTTPError } from "@fosscord/util";
 import fetch from "node-fetch";
 import cheerio from "cheerio";
 import { MessageCreateSchema } from "../../routes/channels/#channel_id/messages";
+import { OrmUtils } from "@fosscord/util";
 const allow_empty = false;
 // TODO: check webhook, application, system author, stickers
 // TODO: embed gifs/videos/images
@@ -47,7 +48,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 	const channel = await Channel.findOneOrFail({ where: { id: opts.channel_id }, relations: ["recipients"] });
 	if (!channel || !opts.channel_id) throw new HTTPError("Channel not found", 404);
 
-	const message = Object.assign(new Message(), {
+	const message = OrmUtils.mergeDeep(new Message(), {
 		...opts,
 		sticker_items: opts.sticker_ids?.map((x) => ({ id: x })),
 		guild_id: channel.guild_id,
@@ -132,9 +133,9 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 		}
 	}
 
-	message.mention_channels = mention_channel_ids.map((x) => Object.assign(new Channel(), { id: x }));
-	message.mention_roles = mention_role_ids.map((x) => Object.assign(new Role(), { id: x }));
-	message.mentions = mention_user_ids.map((x) => Object.assign(new User(), { id: x }));
+	message.mention_channels = mention_channel_ids.map((x) => OrmUtils.mergeDeep(new Channel(), { id: x }));
+	message.mention_roles = mention_role_ids.map((x) => OrmUtils.mergeDeep(new Role(), { id: x }));
+	message.mentions = mention_user_ids.map((x) => OrmUtils.mergeDeep(new User(), { id: x }));
 	message.mention_everyone = mention_everyone;
 
 	// TODO: check and put it all in the body