Add real chatMessageSchema

This commit is contained in:
Alex Gleason 2023-05-04 11:31:58 -05:00
parent 074c3c5b39
commit a7e1350a65
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 20 additions and 4 deletions

View file

@ -1,9 +1,25 @@
import { z } from 'zod';
import { normalizeChatMessage } from 'soapbox/normalizers';
import { toSchema } from 'soapbox/utils/normalizers';
import { attachmentSchema } from './attachment';
import { cardSchema } from './card';
import { customEmojiSchema } from './custom-emoji';
import { emojiSchema, filteredArray } from './utils';
const chatMessageSchema = toSchema(normalizeChatMessage);
const chatMessageSchema = z.object({
account_id: z.string(),
media_attachments: filteredArray(attachmentSchema),
card: cardSchema.nullable().catch(null),
chat_id: z.string(),
content: z.string().catch(''),
created_at: z.string().datetime().catch(new Date().toUTCString()),
emojis: filteredArray(customEmojiSchema),
expiration: z.number().optional().catch(undefined),
emoji_reactions: z.array(emojiSchema).min(1).nullable().catch(null),
id: z.string(),
unread: z.coerce.boolean(),
deleting: z.coerce.boolean(),
pending: z.coerce.boolean(),
});
type ChatMessage = z.infer<typeof chatMessageSchema>;

View file

@ -5,7 +5,7 @@ const historySchema = z.object({
uses: z.coerce.number(),
});
/** // https://docs.joinmastodon.org/entities/tag */
/** https://docs.joinmastodon.org/entities/tag */
const tagSchema = z.object({
name: z.string().min(1),
url: z.string().url().catch(''),