Something went wrong. Try again.
A decentralized music tracking and discovery platform built on AT Protocol 🎵 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243import type { ShareItem } from "./shareLinks";
type Profile = { did: string; displayName?: string; handle?: string; avatar?: string | null;};const handleOf = (value?: string) => value?.trim().replace(/^@+/, "") || "";
/** Catalog records belong to an indexer, not necessarily the person sharing. */export function shareCardActor(item: ShareItem, viewerDid: string): string { if (item.owner?.did) return item.owner.did; if (item.kind === "scrobble") return ( /^at:\/\/([^/]+)\/app\.rocksky\.scrobble\//.exec(item.uri)?.[1] || "" ); if (["profile", "wrapped", "chart"].includes(item.kind)) return item.uri.replace(/^at:\/\//, ""); return viewerDid;}
/** Never borrow a different listener's name while the owner is loading. */export function shareCardIdentity( actor: string, ...profiles: (Profile | null | undefined)[]) { const matching = profiles.filter( (p): p is Profile => !!actor && !!p && (p.did === actor || handleOf(p.handle) === actor), ); const handle = matching.map((p) => handleOf(p.handle)).find(Boolean) || ""; const resolved = matching.find((p) => p.displayName !== undefined); const picture = matching.find((p) => p.avatar !== undefined); return { avatar: picture?.avatar?.trim() || "", displayName: resolved?.displayName?.trim() || handle, handle: handle ? `@${handle}` : "", // Wait for the owner’s name and avatar (including a known missing avatar). ready: !!handle && !!resolved && !!picture, };}