mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-06 10:52:31 +01:00
Update index.ts
This commit is contained in:
parent
d1f24b2537
commit
785544e1c8
@ -1,4 +1,4 @@
|
||||
import { Channel, emitEvent, getPermission, MessageDeleteEvent, Message, MessageUpdateEvent } from "@fosscord/util";
|
||||
import { Channel, emitEvent, getPermission, getRight MessageDeleteEvent, Message, MessageUpdateEvent } from "@fosscord/util";
|
||||
import { Router, Response, Request } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { handleMessage, postHandleMessage } from "@fosscord/api";
|
||||
@ -7,7 +7,7 @@ import { MessageCreateSchema } from "../index";
|
||||
const router = Router();
|
||||
// TODO: message content/embed string length limit
|
||||
|
||||
router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES" }), async (req: Request, res: Response) => {
|
||||
router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES", right: "SEND_MESSAGES" }), async (req: Request, res: Response) => {
|
||||
const { message_id, channel_id } = req.params;
|
||||
var body = req.body as MessageCreateSchema;
|
||||
|
||||
@ -15,10 +15,13 @@ router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGE
|
||||
|
||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
||||
|
||||
if (req.user_id !== message.author_id) {
|
||||
const rights = await getRights(req.user_id);
|
||||
|
||||
if ((req.user_id !== message.author_id)) {
|
||||
if (rights.has("MANAGE_MESSAGES")) break;
|
||||
permissions.hasThrow("MANAGE_MESSAGES");
|
||||
body = { flags: body.flags }; // admins can only suppress embeds of other messages
|
||||
}
|
||||
} else rights.hasThrow("SELF_EDIT_MESSAGES");
|
||||
|
||||
const new_message = await handleMessage({
|
||||
...message,
|
||||
@ -46,17 +49,17 @@ router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGE
|
||||
return res.json(message);
|
||||
});
|
||||
|
||||
// permission check only if deletes messagr from other user
|
||||
router.delete("/", route({}), async (req: Request, res: Response) => {
|
||||
const { message_id, channel_id } = req.params;
|
||||
|
||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||
const message = await Message.findOneOrFail({ id: message_id });
|
||||
|
||||
if (message.author_id !== req.user_id) {
|
||||
if ((message.author_id !== req.user_id)) {
|
||||
if (rights.has("MANAGE_MESSAGES")) break;
|
||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
||||
permission.hasThrow("MANAGE_MESSAGES");
|
||||
}
|
||||
} else rights.hasThrow("SELF_DELETE_MESSAGES");
|
||||
|
||||
await Message.delete({ id: message_id });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user