import type { Group } from "@rakazo/contracts"; import { IntakeBlockSchema } from "@rakazo/contracts"; import { ACTIVE_RUN_STATUSES } from "@rakazo/core"; export const activeRunStatuses = [...ACTIVE_RUN_STATUSES]; export const activeRunSelection = { where: { status: { in: activeRunStatuses } }, orderBy: { createdAt: "desc" as const }, take: 1, select: { status: true }, } as const; export function previewFromBlocks(blocks: unknown): string { const rows = Array.isArray(blocks) ? blocks : []; for (const block of rows) { if ( block && typeof block === "object" && "text" in block && typeof (block as { text?: unknown }).text === "string" ) { return (block as { text: string }).text; } } return ""; } /** * A group's preview of its latest message. An onboarding card or note comes along as * `previewBlock`, so the web can word the preview in the user's language. */ export function groupPreview(blocks: unknown): Pick { const intake = IntakeBlockSchema.safeParse(Array.isArray(blocks) ? blocks[0] : undefined); return { preview: previewFromBlocks(blocks), ...(intake.success ? { previewBlock: intake.data } : {}), }; }