2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
import { customEmojiSchema } from './custom-emoji';
|
|
|
|
import { mediaAttachmentSchema } from './media-attachment';
|
|
|
|
import { previewCardSchema } from './preview-card';
|
2024-10-16 08:03:27 -07:00
|
|
|
import { datetimeSchema, filteredArray } from './utils';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-29 14:26:53 -07:00
|
|
|
/**
|
|
|
|
* @category Schemas
|
|
|
|
* @see {@link https://docs.pleroma.social/backend/development/API/chats/#getting-the-messages-for-a-chat}
|
|
|
|
*/
|
2024-10-13 15:25:30 -07:00
|
|
|
const chatMessageSchema = v.object({
|
|
|
|
id: v.string(),
|
|
|
|
content: v.fallback(v.string(), ''),
|
|
|
|
chat_id: v.string(),
|
|
|
|
account_id: v.string(),
|
2024-10-16 08:03:27 -07:00
|
|
|
created_at: datetimeSchema,
|
2024-08-28 04:43:23 -07:00
|
|
|
emojis: filteredArray(customEmojiSchema),
|
2024-10-13 15:25:30 -07:00
|
|
|
attachment: v.fallback(v.nullable(mediaAttachmentSchema), null),
|
|
|
|
unread: v.boolean(),
|
|
|
|
card: v.fallback(v.nullable(previewCardSchema), null),
|
2024-08-28 04:43:23 -07:00
|
|
|
});
|
|
|
|
|
2024-11-29 07:01:54 -08:00
|
|
|
/**
|
|
|
|
* @category Entity types
|
|
|
|
*/
|
2024-10-13 15:25:30 -07:00
|
|
|
type ChatMessage = v.InferOutput<typeof chatMessageSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
export { chatMessageSchema, type ChatMessage };
|