Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

TimelineUserMessageRow.logic.ts

25 lines1.1 KB

1import { type ChatImageAttachment } from "../../types";
2import type { ComposerContextRecord, KnownComposerContextRecord } from "@t3tools/contracts";
3import { asKnownContextRecord } from "~/lib/composerContextRecords";
4​
5export function resolvePreviewAnnotationImage(input: {
6 record: Extract<KnownComposerContextRecord, { kind: "preview-annotation" }>;
7 recordsById: ReadonlyMap<string, ComposerContextRecord>;
8 userImages: ReadonlyArray<ChatImageAttachment>;
9 previewImages: ReadonlyArray<ChatImageAttachment>;
10 annotationRecordIds: ReadonlyArray<string>;
11}): ChatImageAttachment | null {
12 const screenshotRecord = input.record.screenshotContextId
13 ? asKnownContextRecord(input.recordsById.get(input.record.screenshotContextId))
14 : undefined;
15 return (
16 (screenshotRecord?.kind === "image"
17 ? input.userImages.find((image) => image.id === screenshotRecord.attachmentId)
18 : undefined) ??
19 input.previewImages.find(
20 (image) => image.name === `preview-annotation-${input.record.annotationId}.png`,
21 ) ??
22 input.previewImages[input.annotationRecordIds.indexOf(input.record.contextId)] ??
23 null
24 );