Support deleting ACKs for type==channel

This commit is contained in:
Rory&
2025-12-02 18:06:00 +01:00
parent 563d3a4e7f
commit 5075837d55
4 changed files with 48 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -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;

View File

@@ -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,
}