diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-13 01:11:03 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-13 01:11:03 +0200 |
commit | 07ba78d391ac517225d3afa537d7eb4f7b13c74d (patch) | |
tree | 82d127530d0d837ad1fdf2ef7b76eda122257bcc /api/src/routes | |
parent | :bug: fix channel events + message send (diff) | |
download | server-07ba78d391ac517225d3afa537d7eb4f7b13c74d.tar.xz |
:bug: fix dm #321
Diffstat (limited to 'api/src/routes')
-rw-r--r-- | api/src/routes/channels/#channel_id/permissions.ts | 4 | ||||
-rw-r--r-- | api/src/routes/users/@me/channels.ts | 16 |
2 files changed, 10 insertions, 10 deletions
diff --git a/api/src/routes/channels/#channel_id/permissions.ts b/api/src/routes/channels/#channel_id/permissions.ts index 827e46f2..959ab8e0 100644 --- a/api/src/routes/channels/#channel_id/permissions.ts +++ b/api/src/routes/channels/#channel_id/permissions.ts @@ -35,7 +35,7 @@ router.put( allow: body.allow, deny: body.deny }; - channel.permission_overwrites.push(overwrite); + channel.permission_overwrites!.push(overwrite); } overwrite.allow = body.allow; overwrite.deny = body.deny; @@ -60,7 +60,7 @@ router.delete("/:overwrite_id", route({ permission: "MANAGE_ROLES" }), async (re const channel = await Channel.findOneOrFail({ id: channel_id }); if (!channel.guild_id) throw new HTTPError("Channel not found", 404); - channel.permission_overwrites = channel.permission_overwrites.filter((x) => x.id === overwrite_id); + channel.permission_overwrites = channel.permission_overwrites!.filter((x) => x.id === overwrite_id); await Promise.all([ channel.save(), diff --git a/api/src/routes/users/@me/channels.ts b/api/src/routes/users/@me/channels.ts index 5515a217..da33f204 100644 --- a/api/src/routes/users/@me/channels.ts +++ b/api/src/routes/users/@me/channels.ts @@ -4,11 +4,6 @@ import { HTTPError } from "lambert-server"; import { route } from "@fosscord/api"; import { In } from "typeorm"; -export interface DmChannelCreateSchema { - name?: string; - recipients: string[]; -} - const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { @@ -17,12 +12,17 @@ router.get("/", route({}), async (req: Request, res: Response) => { res.json(recipients.map((x) => x.channel)); }); +export interface DmChannelCreateSchema { + name?: string; + recipients: string[]; +} + router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request, res: Response) => { const body = req.body as DmChannelCreateSchema; body.recipients = body.recipients.filter((x) => x !== req.user_id).unique(); - const recipients = await User.find({ id: In(body.recipients) }); + const recipients = await User.find({ where: body.recipients.map((x) => ({ id: x })) }); if (recipients.length !== body.recipients.length) { throw new HTTPError("Recipient/s not found"); @@ -34,10 +34,10 @@ router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request, const channel = await new Channel({ name, type, - owner_id: req.user_id, + // owner_id only for group dm channels created_at: new Date(), last_message_id: null, - recipients: [...body.recipients.map((x) => new Recipient({ id: x })), new Recipient({ id: req.user_id })] + recipients: [...body.recipients.map((x) => new Recipient({ user_id: x })), new Recipient({ user_id: req.user_id })] }).save(); await emitEvent({ event: "CHANNEL_CREATE", data: channel, user_id: req.user_id } as ChannelCreateEvent); |