bigbuffet-rw/app/soapbox/schemas/chat-message.ts

26 lines
899 B
TypeScript
Raw Normal View History

2023-05-04 08:24:34 -07:00
import { z } from 'zod';
2023-05-04 09:31:58 -07:00
import { attachmentSchema } from './attachment';
import { cardSchema } from './card';
import { customEmojiSchema } from './custom-emoji';
2023-05-04 09:42:20 -07:00
import { contentSchema, emojiSchema, filteredArray } from './utils';
2023-05-04 08:24:34 -07:00
2023-05-04 09:31:58 -07:00
const chatMessageSchema = z.object({
account_id: z.string(),
media_attachments: filteredArray(attachmentSchema),
card: cardSchema.nullable().catch(null),
chat_id: z.string(),
2023-05-04 09:42:20 -07:00
content: contentSchema,
2023-05-04 09:31:58 -07:00
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(),
});
2023-05-04 08:24:34 -07:00
type ChatMessage = z.infer<typeof chatMessageSchema>;
export { chatMessageSchema, type ChatMessage };