diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-18 11:48:51 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-18 11:48:51 +0200 |
commit | 5c220fcc83afcb3e63a33389ccaccc9a15081b4a (patch) | |
tree | 2b5493054a6dae282e300d92ec636b5f8d348382 /api | |
parent | :bug: fix findOneAndUpdate (diff) | |
download | server-5c220fcc83afcb3e63a33389ccaccc9a15081b4a.tar.xz |
fix #199
Diffstat (limited to 'api')
-rw-r--r-- | api/src/routes/channels/#channel_id/messages/#message_id/index.ts | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts b/api/src/routes/channels/#channel_id/messages/#message_id/index.ts index 6337a1b7..35952d26 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts +++ b/api/src/routes/channels/#channel_id/messages/#message_id/index.ts @@ -12,23 +12,26 @@ router.patch("/", check(MessageCreateSchema), async (req: Request, res: Response const { message_id, channel_id } = req.params; var body = req.body as MessageCreateSchema; - var message = await MessageModel.findOne({ id: message_id, channel_id }, { author_id: true }).exec(); + var message = await MessageModel.findOne({ id: message_id, channel_id }, { author_id: true, message_reference: true }).lean().exec(); const permissions = await getPermission(req.user_id, undefined, channel_id); if (req.user_id !== message.author_id) { permissions.hasThrow("MANAGE_MESSAGES"); - body = { flags: body.flags }; + body = { flags: body.flags }; // admins can only suppress embeds of other messages } const opts = await handleMessage({ + message_reference: message.message_reference, ...body, - ...message, + author_id: message.author_id, + channel_id, + id: message_id, edited_timestamp: new Date() }); // @ts-ignore - message = await MessageModel.findOneAndUpdate({ id: message_id }, opts).populate("author").exec(); + message = await MessageModel.findOneAndUpdate({ id: message_id }, opts, { new: true }).populate("author").exec(); await emitEvent({ event: "MESSAGE_UPDATE", |