From 71258f64879b43c3bf365c92bcb9d3b61b634f15 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Mon, 30 Jan 2023 13:34:27 +1100 Subject: [PATCH] read-states/ack-bulk (#969) --- assets/openapi.json | Bin 222559 -> 226065 bytes assets/schemas.json | Bin 1091332 -> 1092544 bytes src/api/routes/read-states/ack-bulk.ts | 41 +++++++++++++++++++++++++ src/util/schemas/AckBulkSchema.ts | 9 ++++++ src/util/schemas/index.ts | 15 +++++++++ 5 files changed, 65 insertions(+) create mode 100644 src/api/routes/read-states/ack-bulk.ts create mode 100644 src/util/schemas/AckBulkSchema.ts diff --git a/assets/openapi.json b/assets/openapi.json index 0eafe6cbae6fedae62e5184b492b314588979607..7cb270b1cca178257e8ffc1434afd3d47d6de0c3 100644 GIT binary patch delta 451 zcmcbAig)5O-i9rVdKT=C$=Ob&IoXpRwkB~Fr6#7t7ndZKOuo2RW6~te$#u^?CtsMQ zI(fr=*2xW3+LIUPa86Dr*Pp!Mo8TmCjmaODDuaa{BymiBQ>Kn2JpIE4CT>osX{qs( z8}k$=PvDlEK7oT#ce=q2CONQPps|xQWhTq}NP*OgOg>Pj1h#5HKKJy0TFg?@8<-e* zCj(8N{#%k+7R=*;yD>GsWb#5+NuaSjlNVHqO>c-`lml{DCMRrApZwoXdUEX%p2>Rt zVv_}&Jvd;xrXM)MXxy%6!3e}m+x0A%HFc*e)G&&P=cXm7X=_ePZrljVT zWG3cJXY6PEI&C_W!1N2!%#zy;6q)iFdBRhZ96{;=@{3ERPfTWfB#A|5v3_-SYUOmr zwT$A^AGkBgOkWVic#0V$l&H@13e0G{#~3^PLp7s~Ajn#MWG76&7{aVOJs_O%H3!VL R>3^-6Pjhf706{HREdY(WuYv#o delta 34 ncmbREjQ9R2-i9rVdKT?-Z5e@>Y5QDTW=&lVE(IW{<*Ee$=>-cL diff --git a/assets/schemas.json b/assets/schemas.json index c840b2612291e3723a14585f3a3a2a0a35914617..f40bcd7906cfdceb54ed185ea7eb305819e734e9 100644 GIT binary patch delta 240 zcmZoU=XBt@6JIr#0uU%UCTBa9=44M6tfc zFHqsvnw}8M9yQs(#&vo^2qX7&D=%iL$pWFQU`>-9$W5P+1ymVV91d|)<8FTO>9>7Z92(hM*%@2enOfPITiID!*;!lJ*;?6wf*h^v doUQC!t?b;b>^!aPyshkft?c|;*#-VC0|0s3PJ{pe delta 77 zcmX?b-KpiA6JvGrUY7Q~EQ~a{@6J5OV`D4-oSLF&_}~ LZ{N!zz`Ps)T^1V< diff --git a/src/api/routes/read-states/ack-bulk.ts b/src/api/routes/read-states/ack-bulk.ts new file mode 100644 index 00000000..f77ecedf --- /dev/null +++ b/src/api/routes/read-states/ack-bulk.ts @@ -0,0 +1,41 @@ +import { Router, Request, Response } from "express"; +import { route } from "@fosscord/api"; +import { AckBulkSchema, ReadState } from "@fosscord/util"; +const router = Router(); + +router.post( + "/", + route({ body: "AckBulkSchema" }), + async (req: Request, res: Response) => { + const body = req.body as AckBulkSchema; + + // TODO: what is read_state_type ? + + await Promise.all([ + // for every new state + ...body.read_states.map(async (x) => { + // find an existing one + const ret = + (await ReadState.findOne({ + where: { + user_id: req.user_id, + channel_id: x.channel_id, + }, + })) ?? + // if it doesn't exist, create it (not a promise) + ReadState.create({ + user_id: req.user_id, + channel_id: x.channel_id, + }); + + ret.last_message_id = x.message_id; + + return ret.save(); + }), + ]); + + return res.status(204); + }, +); + +export default router; diff --git a/src/util/schemas/AckBulkSchema.ts b/src/util/schemas/AckBulkSchema.ts new file mode 100644 index 00000000..8e20723f --- /dev/null +++ b/src/util/schemas/AckBulkSchema.ts @@ -0,0 +1,9 @@ +export interface AckBulkSchema { + read_states: [ + { + channel_id: string; + message_id: string; + read_state_type: number; // WHat is this? + }, + ]; +} diff --git a/src/util/schemas/index.ts b/src/util/schemas/index.ts index 65e8b3cd..603141b5 100644 --- a/src/util/schemas/index.ts +++ b/src/util/schemas/index.ts @@ -69,6 +69,21 @@ export * from "./VanityUrlSchema"; export * from "./VoiceIdentifySchema"; export * from "./VoiceStateUpdateSchema"; export * from "./VoiceVideoSchema"; +export * from "./IdentifySchema"; +export * from "./ActivitySchema"; +export * from "./LazyRequestSchema"; +export * from "./GuildUpdateSchema"; +export * from "./ChannelPermissionOverwriteSchema"; +export * from "./UserGuildSettingsSchema"; +export * from "./GatewayPayloadSchema"; +export * from "./RolePositionUpdateSchema"; +export * from "./ChannelReorderSchema"; +export * from "./UserSettingsSchema"; +export * from "./BotModifySchema"; +export * from "./ApplicationModifySchema"; +export * from "./ApplicationCreateSchema"; +export * from "./ApplicationAuthorizeSchema"; +export * from "./AckBulkSchema"; export * from "./WebAuthnSchema"; export * from "./WebhookCreateSchema"; export * from "./WidgetModifySchema";