101 lines
3.3 KiB
TypeScript
101 lines
3.3 KiB
TypeScript
import type { FromSchema } from 'json-schema-to-ts';
|
|
import { mediaRefSchema } from './media';
|
|
|
|
const USERNAME_PATTERN = '^[a-zA-Z0-9_]{3,32}$';
|
|
|
|
export const createDirectBodySchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['username'],
|
|
properties: {
|
|
username: { type: 'string', pattern: USERNAME_PATTERN },
|
|
},
|
|
} as const;
|
|
|
|
export const createGroupBodySchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['title'],
|
|
properties: {
|
|
title: { type: 'string', minLength: 1, maxLength: 100 },
|
|
members: {
|
|
type: 'array',
|
|
maxItems: 200,
|
|
items: { type: 'string', pattern: USERNAME_PATTERN },
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
// A channel: broadcast conversation; members are subscribers, only the owner
|
|
// and admins post. Description is optional (shown on the channel info page).
|
|
export const createChannelBodySchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['title'],
|
|
properties: {
|
|
title: { type: 'string', minLength: 1, maxLength: 100 },
|
|
description: { type: 'string', maxLength: 500 },
|
|
members: {
|
|
type: 'array',
|
|
maxItems: 200,
|
|
items: { type: 'string', pattern: USERNAME_PATTERN },
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
export const addMemberBodySchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['username'],
|
|
properties: {
|
|
username: { type: 'string', pattern: USERNAME_PATTERN },
|
|
},
|
|
} as const;
|
|
|
|
export const sendMessageBodySchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['clientMsgId'],
|
|
properties: {
|
|
// Caption; may be empty for a media-only message.
|
|
content: { type: 'string', maxLength: 16000 },
|
|
clientMsgId: { type: 'string', minLength: 1, maxLength: 64 },
|
|
contentType: { type: 'string', enum: ['text', 'text/ciphertext'] },
|
|
encryption: { type: ['string', 'null'] },
|
|
// Object key returned by the media upload URL + its metadata.
|
|
mediaKey: { type: 'string', minLength: 1, maxLength: 255 },
|
|
media: mediaRefSchema,
|
|
// Reply target message id (must be in the same conversation).
|
|
replyToId: { type: 'string', format: 'uuid' },
|
|
},
|
|
} as const;
|
|
|
|
// Forward a message into the target conversation (the route's :id).
|
|
export const forwardMessageBodySchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['sourceConversationId', 'messageId'],
|
|
properties: {
|
|
sourceConversationId: { type: 'string', format: 'uuid' },
|
|
messageId: { type: 'string', format: 'uuid' },
|
|
// When true the original author is hidden ("Hidden account") on the forward.
|
|
hideSender: { type: 'boolean' },
|
|
},
|
|
} as const;
|
|
|
|
export const addContactBodySchema = {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['username'],
|
|
properties: {
|
|
username: { type: 'string', pattern: USERNAME_PATTERN },
|
|
},
|
|
} as const;
|
|
|
|
export type ForwardMessageBody = FromSchema<typeof forwardMessageBodySchema>;
|
|
export type CreateDirectBody = FromSchema<typeof createDirectBodySchema>;
|
|
export type CreateGroupBody = FromSchema<typeof createGroupBodySchema>;
|
|
export type CreateChannelBody = FromSchema<typeof createChannelBodySchema>;
|
|
export type AddMemberBody = FromSchema<typeof addMemberBodySchema>;
|
|
export type SendMessageBody = FromSchema<typeof sendMessageBodySchema>;
|
|
export type AddContactBody = FromSchema<typeof addContactBodySchema>;
|