mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-25 11:43:07 +01:00
read-states/ack-bulk (#969)
This commit is contained in:
parent
1e21802064
commit
4906d9a78a
@ -2316,6 +2316,41 @@
|
||||
"days"
|
||||
]
|
||||
},
|
||||
"AckBulkSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"read_states": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"channel_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"message_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"read_state_type": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"channel_id",
|
||||
"message_id",
|
||||
"read_state_type"
|
||||
]
|
||||
}
|
||||
],
|
||||
"minItems": 1,
|
||||
"maxItems": 1
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"read_states"
|
||||
]
|
||||
},
|
||||
"TransportMakeRequestResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@ -7030,6 +7065,78 @@
|
||||
"read-states"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/users/@me/mfa/webauthn/credentials/": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"bearer": true
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"users"
|
||||
]
|
||||
},
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"bearer": true
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/WebAuthnPostSchema"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"users"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/users/@me/mfa/webauthn/credentials/{key_id}/": {
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"bearer": true
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "key_id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "key_id"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"users"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/auth/mfa/webauthn/": {
|
||||
"post": {
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/WebAuthnTotpSchema"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"auth"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,41 @@
|
||||
{
|
||||
"AckBulkSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"read_states": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"channel_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"message_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"read_state_type": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"channel_id",
|
||||
"message_id",
|
||||
"read_state_type"
|
||||
]
|
||||
}
|
||||
],
|
||||
"minItems": 1,
|
||||
"maxItems": 1
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"read_states"
|
||||
],
|
||||
"$schema": "http://json-schema.org/draft-07/schema#"
|
||||
},
|
||||
"TransportMakeRequestResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
41
src/api/routes/read-states/ack-bulk.ts
Normal file
41
src/api/routes/read-states/ack-bulk.ts
Normal file
@ -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;
|
9
src/util/schemas/AckBulkSchema.ts
Normal file
9
src/util/schemas/AckBulkSchema.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export interface AckBulkSchema {
|
||||
read_states: [
|
||||
{
|
||||
channel_id: string;
|
||||
message_id: string;
|
||||
read_state_type: number; // WHat is this?
|
||||
},
|
||||
];
|
||||
}
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user