diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-02-13 22:29:14 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-02-13 22:29:14 +1100 |
commit | 204fe2aed1ebaed98a842db785851eb4f64bc2be (patch) | |
tree | dbcbf5863f6ffe86d544608d5c206b207c6df307 /api/src/routes/channels/#channel_id/messages/index.ts | |
parent | ;jondfgsk (diff) | |
parent | Appropriate DB charset (#629) (diff) | |
download | server-204fe2aed1ebaed98a842db785851eb4f64bc2be.tar.xz |
Merge branch 'master' into maddyrtc
Diffstat (limited to 'api/src/routes/channels/#channel_id/messages/index.ts')
-rw-r--r-- | api/src/routes/channels/#channel_id/messages/index.ts | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts index c3d3d408..2fd08b04 100644 --- a/api/src/routes/channels/#channel_id/messages/index.ts +++ b/api/src/routes/channels/#channel_id/messages/index.ts @@ -37,7 +37,11 @@ export function isTextChannel(type: ChannelType): boolean { case ChannelType.GUILD_PUBLIC_THREAD: case ChannelType.GUILD_PRIVATE_THREAD: case ChannelType.GUILD_TEXT: + case ChannelType.ENCRYPTED: + case ChannelType.ENCRYPTED_THREAD: return true; + default: + throw new HTTPError("unimplemented", 400); } } @@ -87,7 +91,7 @@ router.get("/", async (req: Request, res: Response) => { permissions.hasThrow("VIEW_CHANNEL"); if (!permissions.has("READ_MESSAGE_HISTORY")) return res.json([]); - var query: FindManyOptions<Message> & { where: { id?: any } } = { + var query: FindManyOptions<Message> & { where: { id?: any; }; } = { order: { id: "DESC" }, take: limit, where: { channel_id }, @@ -122,6 +126,13 @@ router.get("/", async (req: Request, res: Response) => { y.proxy_url = `${endpoint == null ? "" : endpoint}${new URL(uri).pathname}`; }); + //Some clients ( discord.js ) only check if a property exists within the response, + //which causes erorrs when, say, the `application` property is `null`. + for (var curr in x) { + if (x[curr] === null) + delete x[curr]; + } + return x; }) ); @@ -208,7 +219,10 @@ router.post( }) ); } - + + //Fix for the client bug + delete message.member + await Promise.all([ message.save(), emitEvent({ event: "MESSAGE_CREATE", channel_id: channel_id, data: message } as MessageCreateEvent), @@ -216,7 +230,7 @@ router.post( channel.save() ]); - postHandleMessage(message).catch((e) => {}); // no await as it shouldnt block the message send function and silently catch error + postHandleMessage(message).catch((e) => { }); // no await as it shouldnt block the message send function and silently catch error return res.json(message); } |