import { z } from "zod"; import { mastodonAccountSchema } from "../account/schema"; const mastodonMediaAttachmentSchema = z.object({ id: z.string(), type: z.enum(["audio", "image", "video", "gifv", "unknown"]), url: z.string(), preview_url: z.string().optional(), remote_url: z.string().optional(), meta: z.record(z.string(), z.any()), description: z.string().optional(), blurhash: z.string().optional(), }); const mastodonEmojiSchema = z.object({ shortcode: z.string(), url: z.string(), static_url: z.string(), visible_in_picker: z.boolean(), category: z.string().optional(), }); const mastodonPreviewCardSchema = z.object({ url: z.string(), title: z.string(), description: z.string(), type: z.enum(["link", "photo", "video", "rich"]), author_name: z.string(), author_url: z.string(), provider_name: z.string(), provider_url: z.string(), html: z.string(), width: z.number(), height: z.number(), image: z.string().optional(), embed_url: z.string(), blurhash: z.string().optional(), }); const mastodonPollSchema = z.object({ id: z.string(), expires_at: z.string(), expired: z.boolean(), multiple: z.boolean(), votes_count: z.number(), options: z.array( z.object({ title: z.string(), votes_count: z.number(), }), ), voted: z.boolean().optional(), own_votes: z.array(z.number()).optional(), emojis: z.array(mastodonEmojiSchema), }); type MastodonStatusSchemaType = { id: string; uri: string; created_at: string; account: z.infer; content: string; visibility: "public" | "unlisted" | "private" | "direct"; sensitive: boolean; media_attachments: Array>; application?: { name: string; website?: string; }; mentions: Array<{ id: string; username: string; acct: string; url: string; }>; tags: Array<{ name: string; url: string; }>; emojis: Array>; reblogs_count: number; favourites_count: number; replies_count: number; url: string; in_reply_to_id?: string; in_reply_to_account_id?: string; reblog?: MastodonStatusSchemaType; poll?: z.infer; card?: z.infer; language?: string; text?: string; edited_at?: string; favourited?: boolean; reblogged?: boolean; muted?: boolean; bookmarked?: boolean; pinned?: boolean; }; export const mastodonStatusSchema: z.ZodType = z.lazy(() => z.object({ id: z.string(), uri: z.string(), created_at: z.string(), account: mastodonAccountSchema, content: z.string(), visibility: z.enum(["public", "unlisted", "private", "direct"]), sensitive: z.boolean(), media_attachments: z.array(mastodonMediaAttachmentSchema), application: z .object({ name: z.string(), website: z.string().optional(), }) .optional(), mentions: z.array( z.object({ id: z.string(), username: z.string(), acct: z.string(), url: z.string(), }), ), tags: z.array( z.object({ name: z.string(), url: z.string(), }), ), emojis: z.array(mastodonEmojiSchema), reblogs_count: z.number(), favourites_count: z.number(), replies_count: z.number(), url: z.string(), in_reply_to_id: z.string().optional(), in_reply_to_account_id: z.string().optional(), reblog: mastodonStatusSchema.optional(), poll: mastodonPollSchema.optional(), card: mastodonPreviewCardSchema.optional(), language: z.string().optional(), text: z.string().optional(), edited_at: z.string().optional(), favourited: z.boolean().optional(), reblogged: z.boolean().optional(), muted: z.boolean().optional(), bookmarked: z.boolean().optional(), pinned: z.boolean().optional(), }), ); export type MastodonStatusSchema = MastodonStatusSchemaType; export const mastodonStatusArraySchema = z.array(mastodonStatusSchema); export type MastodonStatusArraySchema = z.infer;