Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import { actorProfile, followerCount, listProjects, listTangledRepos, myFollow, resolveActor, type Actor, type ActorProfile, type Session, type TangledRepoSummary,} from "@nibling/sdk";import { avatarUrlOf } from "../platform/state.ts";import { cardFromProject, handled, newestFirst, type ProjectCard } from "./cards.ts";
export interface ActorPageData { readonly actor: Actor; /** The handle when it resolved, else the DID. */ readonly name: string; readonly profile: ActorProfile; /** A URL for the avatar blob, on the gateway or the account's PDS. */ readonly avatarUrl?: string; readonly viewer?: ActorViewer; /** The rest fills in after the profile shows. */ readonly projects: Promise<ActorProjects>; readonly tangledRepos: Promise<readonly TangledRepoSummary[]>; /** Undefined when Constellation is unavailable. */ readonly followers: Promise<number | undefined>;}
export interface ActorProjects { /** Pinned projects, in pinned order. Pins that name no listed project are dropped. */ readonly pinned: readonly ProjectCard[]; /** Every project, newest first. */ readonly projects: readonly ProjectCard[];}
/** How the signed-in account relates to the page. `follow` is the viewer's follow record, once it is known. */export type ActorViewer = | { readonly kind: "self" } | { readonly kind: "other"; readonly follow: Promise<string | undefined> };
/** Resolves once the profile is read; projects, repos, and counts are promises the page renders as they land. */export async function loadActorPage(identifier: string, viewer?: Session): Promise<ActorPageData> { // Everything after the DID starts at once; the profile is all the page waits for. const actor = await resolveActor(identifier); const name = actor.handle ?? actor.did; const profile = actorProfile(actor.did).then((page) => page.profile); const projects = handled( Promise.all([listProjects(actor.did), profile]).then(([list, { pinned }]) => { const cards = list.map((project) => cardFromProject(project, name)).sort(newestFirst); const byUri = new Map(cards.map((card) => [card.uri, card])); return { pinned: pinned.flatMap((ref) => byUri.get(ref.uri) ?? []), projects: cards }; }), ); const rest = { projects, tangledRepos: handled(listTangledRepos(actor)), followers: followerCount(actor.did).catch(() => undefined), ...(viewer ? { viewer: viewerOf(viewer, actor) } : {}), }; const shown = await profile; const avatarUrl = avatarUrlOf(actor, shown); return { actor, name, profile: shown, ...(avatarUrl ? { avatarUrl } : {}), ...rest };}
function viewerOf(viewer: Session, actor: Actor): ActorViewer { if (viewer.did === actor.did) return { kind: "self" }; return { kind: "other", follow: myFollow(viewer, actor.did).catch(() => undefined) };}