diff --git a/assets/openapi.json b/assets/openapi.json index d20ef2fb8..5a81a5de1 100644 Binary files a/assets/openapi.json and b/assets/openapi.json differ diff --git a/assets/schemas.json b/assets/schemas.json index bfe3de68c..e092a919f 100644 Binary files a/assets/schemas.json and b/assets/schemas.json differ diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts index d399e53af..8790241d8 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts @@ -18,7 +18,6 @@ import { handleMessage, postHandleMessage, route } from "@spacebar/api"; import { - ApiError, Attachment, AutomodRule, AutomodTriggerTypes, @@ -39,9 +38,9 @@ import { Relationship, Rights, Snowflake, + stringGlobToRegexp, uploadFile, User, - stringGlobToRegexp, } from "@spacebar/util"; import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server"; @@ -49,6 +48,7 @@ import multer from "multer"; import { FindManyOptions, FindOperator, LessThan, MoreThan, MoreThanOrEqual } from "typeorm"; import { URL } from "url"; import { + AcknowledgeDeleteSchema, AutomodCustomWordsRule, AutomodRuleActionType, AutomodRuleEventType, @@ -57,6 +57,7 @@ import { MessageCreateCloudAttachment, MessageCreateSchema, Reaction, + ReadStateType, RelationshipType, } from "@spacebar/schemas"; @@ -532,4 +533,28 @@ router.post( }, ); +router.delete( + "/ack", + route({ + requestBody: "AcknowledgeDeleteSchema", + responses: { + 204: {}, + }, + }), + async (req: Request, res: Response) => { + const { channel_id } = req.params; // not really a channel id if read_state_type != CHANNEL + const body = req.body as AcknowledgeDeleteSchema; + if (body.version != 2) return res.status(204).send(); + // TODO: handle other read state types + if (body.read_state_type != ReadStateType.CHANNEL) return res.status(204).send(); + + const readState = await ReadState.findOne({where: {channel_id}}); + if (readState) { + await readState.remove(); + } + + res.status(204).send(); + }, +); + export default router; diff --git a/src/schemas/uncategorised/MessageAcknowledgeSchema.ts b/src/schemas/uncategorised/MessageAcknowledgeSchema.ts index 3ba716491..891ccc903 100644 --- a/src/schemas/uncategorised/MessageAcknowledgeSchema.ts +++ b/src/schemas/uncategorised/MessageAcknowledgeSchema.ts @@ -19,7 +19,27 @@ export interface MessageAcknowledgeSchema { manual?: boolean; mention_count?: number; - flags?: number; + flags?: ReadStateFlags; last_viewed?: number; token?: string; } + +export interface AcknowledgeDeleteSchema { + read_state_type?: ReadStateType; + version?: number; +} + +export enum ReadStateType { + CHANNEL = 0, + GUILD_EVENT = 1, + NOTIFICATION_CENTER = 2, + GUILD_HOME = 3, + GUILD_ONBOARDING_QUESTION = 4, + MESSAGE_REQUESTS = 5, +} + +export enum ReadStateFlags { + IS_GUILD_CHANNEL = 1 << 0, + IS_THREAD = 1 << 1, + IS_MENTION_LOW_IMPORTANCE = 1 << 2, +} \ No newline at end of file