Add real chatMessageSchema
This commit is contained in:
parent
074c3c5b39
commit
a7e1350a65
2 changed files with 20 additions and 4 deletions
|
@ -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>;
|
||||
|
||||
|
|
|
@ -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(''),
|
||||
|
|
Loading…
Reference in a new issue