summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/read-states/ack-bulk.ts41
-rw-r--r--src/util/schemas/AckBulkSchema.ts9
-rw-r--r--src/util/schemas/index.ts15
3 files changed, 65 insertions, 0 deletions
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";