1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 20:52:42 +01:00
This commit is contained in:
Flam3rboy 2021-08-18 11:48:51 +02:00
parent 4105df8dcb
commit 5c220fcc83

View File

@ -12,23 +12,26 @@ router.patch("/", check(MessageCreateSchema), async (req: Request, res: Response
const { message_id, channel_id } = req.params; const { message_id, channel_id } = req.params;
var body = req.body as MessageCreateSchema; 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); const permissions = await getPermission(req.user_id, undefined, channel_id);
if (req.user_id !== message.author_id) { if (req.user_id !== message.author_id) {
permissions.hasThrow("MANAGE_MESSAGES"); permissions.hasThrow("MANAGE_MESSAGES");
body = { flags: body.flags }; body = { flags: body.flags }; // admins can only suppress embeds of other messages
} }
const opts = await handleMessage({ const opts = await handleMessage({
message_reference: message.message_reference,
...body, ...body,
...message, author_id: message.author_id,
channel_id,
id: message_id,
edited_timestamp: new Date() edited_timestamp: new Date()
}); });
// @ts-ignore // @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({ await emitEvent({
event: "MESSAGE_UPDATE", event: "MESSAGE_UPDATE",