forked from
samuel.fm/statusphere-react
the statusphere demo reworked into a vite/react app in a monorepo
1import {
2 AppBskyActorDefs,
3 AppBskyActorProfile,
4 XyzStatusphereDefs,
5} from '@statusphere/lexicon'
6
7import { AppContext } from '#/context'
8import { Status } from '#/db'
9
10const INVALID_HANDLE = 'handle.invalid'
11
12export async function statusToStatusView(
13 status: Status,
14 ctx: AppContext,
15): Promise<XyzStatusphereDefs.StatusView> {
16 return {
17 uri: status.uri,
18 status: status.status,
19 createdAt: status.createdAt,
20 profile: {
21 did: status.authorDid,
22 handle: await ctx.resolver
23 .resolveDidToHandle(status.authorDid)
24 .then((handle) => (handle.startsWith('did:') ? INVALID_HANDLE : handle))
25 .catch(() => INVALID_HANDLE),
26 },
27 }
28}
29
30export async function bskyProfileToProfileView(
31 did: string,
32 profile: AppBskyActorProfile.Record,
33 ctx: AppContext,
34): Promise<AppBskyActorDefs.ProfileView> {
35 return {
36 $type: 'app.bsky.actor.defs#profileView',
37 did: did,
38 handle: await ctx.resolver.resolveDidToHandle(did),
39 avatar: profile.avatar
40 ? `https://atproto.pictures/img/${did}/${profile.avatar.ref}`
41 : undefined,
42 displayName: profile.displayName,
43 createdAt: profile.createdAt,
44 }
45}