bigbuffet-rw/src/schemas/chat-message.ts

24 lines
761 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';
import { contentSchema, 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),
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 };