Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import type { CommentListPage } from "#lib/api/comment.ts";import type { BobbinContext } from "#lib/api/client.ts";import { INVALID_HANDLE } from "#lib/api/identity.ts";import { orNull } from "#lib/api/load.ts";import type { Sidecar } from "#lib/api/enrich.ts";import { rkeyFromUri } from "#lib/api/uri.ts";import { buildCommentThreads, commentAuthorOf, commentModerationOf, listCommentItems, type CommentThread, type CommentView, type ThreadInput} from "#lib/components/comment/comments.ts";import type { MarkupContext } from "#lib/markup/paths.ts";import { renderMarkup } from "#lib/markup/render.ts";
export const toThreadInputs = async ( items: CommentListPage["items"], docs: Sidecar, markupCtx: MarkupContext, extra?: (uri: string) => Partial<CommentView>): Promise<ThreadInput[]> => Promise.all( items.map(async (item): Promise<ThreadInput> => { const author = commentAuthorOf(docs, item); const body = item.body?.text ?? ""; return { comment: { uri: item.uri, cid: item.cid, rkey: rkeyFromUri(item.uri), authorDid: author.did, authorHandle: author.handle ?? INVALID_HANDLE, moderation: commentModerationOf(docs, item), createdAt: item.createdAt, body, bodyHtml: body ? await orNull(renderMarkup(body, markupCtx)) : null, ...extra?.(item.uri) }, replyTo: item.replyTo?.uri ?? null, replyToCid: item.replyTo?.cid }; }) );
export const loadCommentThreads = async ( ctx: BobbinContext, subjectUri: string, markupCtx: MarkupContext, extra?: (uri: string) => Partial<CommentView>): Promise<CommentThread[]> => { const { items, docs } = await listCommentItems(ctx, subjectUri); return buildCommentThreads(await toThreadInputs(items, docs, markupCtx, extra));};