mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 20:52:42 +01:00
fix #199
This commit is contained in:
parent
4105df8dcb
commit
5c220fcc83
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user