diff options
author | Vincent Junge <specificprotagonist@posteo.org> | 2023-06-26 16:11:03 +0200 |
---|---|---|
committer | Vincent Junge <specificprotagonist@posteo.org> | 2023-06-26 16:11:03 +0200 |
commit | e4a8517b93ecad9dac96dee113103dced81f42f6 (patch) | |
tree | ada83c96958cf0202c9f05bc6ddcc909b528d517 /src/api | |
parent | Merge pull request #1066 from Zert3x/master (diff) | |
download | server-e4a8517b93ecad9dac96dee113103dced81f42f6.tar.xz |
fix get channel messages around parameter
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/routes/channels/#channel_id/messages/index.ts | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts index f031fa75..a15b462d 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts @@ -20,7 +20,6 @@ import { handleMessage, postHandleMessage, route } from "@spacebar/api"; import { Attachment, Channel, - ChannelType, Config, DmChannelDTO, FieldErrors, @@ -93,8 +92,6 @@ router.get( if (limit < 1 || limit > 100) throw new HTTPError("limit must be between 1 and 100", 422); - const halfLimit = Math.floor(limit / 2); - const permissions = await getPermission( req.user_id, channel.guild_id, @@ -121,24 +118,28 @@ router.get( ], }; + let messages: Message[]; if (after) { if (BigInt(after) > BigInt(Snowflake.generate())) return res.status(422); query.where.id = MoreThan(after); + messages = await Message.find(query); } else if (before) { if (BigInt(before) < BigInt(req.params.channel_id)) return res.status(422); query.where.id = LessThan(before); + messages = await Message.find(query); } else if (around) { - query.where.id = [ - MoreThan((BigInt(around) - BigInt(halfLimit)).toString()), - LessThan((BigInt(around) + BigInt(halfLimit)).toString()), - ]; - - return res.json([]); // TODO: fix around + query.take = Math.floor(limit / 2); + query.where.id = LessThan(around); + const messages_before = await Message.find(query); + query.where.id = MoreThan(around); + const messages_after = await Message.find(query); + messages = messages_before.concat(messages_after); + } else { + throw new HTTPError("after, around or before must be present", 422); } - const messages = await Message.find(query); const endpoint = Config.get().cdn.endpointPublic; return res.json( |