tangled
alpha
login
or
join now
graham.systems
/
statusphere-react
forked from
samuel.fm/statusphere-react
0
fork
atom
the statusphere demo reworked into a vite/react app in a monorepo
0
fork
atom
overview
issues
pulls
pipelines
move code to hydrate.ts
samuel.fm
1 year ago
8a3a1fc3
3a2684d7
+24
-14
2 changed files
expand all
collapse all
unified
split
packages
appview
src
lib
hydrate.ts
routes.ts
+22
-1
packages/appview/src/lib/hydrate.ts
···
1
1
-
import { XyzStatusphereDefs } from '@statusphere/lexicon'
1
1
+
import {
2
2
+
AppBskyActorDefs,
3
3
+
AppBskyActorProfile,
4
4
+
XyzStatusphereDefs,
5
5
+
} from '@statusphere/lexicon'
2
6
3
7
import { Status } from '#/db'
4
8
import { AppContext } from '#/index'
···
19
23
},
20
24
}
21
25
}
26
26
+
27
27
+
export async function bskyProfileToProfileView(
28
28
+
did: string,
29
29
+
profile: AppBskyActorProfile.Record,
30
30
+
ctx: AppContext,
31
31
+
): Promise<AppBskyActorDefs.ProfileView> {
32
32
+
return {
33
33
+
$type: 'app.bsky.actor.defs#profileView',
34
34
+
did: did,
35
35
+
handle: await ctx.resolver.resolveDidToHandle(did),
36
36
+
avatar: profile.avatar
37
37
+
? `https://atproto.pictures/img/${did}/${profile.avatar.ref}`
38
38
+
: undefined,
39
39
+
displayName: profile.displayName,
40
40
+
createdAt: profile.createdAt,
41
41
+
}
42
42
+
}
+2
-13
packages/appview/src/routes.ts
···
13
13
14
14
import type { AppContext } from '#/index'
15
15
import { env } from '#/lib/env'
16
16
-
import { statusToStatusView } from '#/lib/hydrate'
16
16
+
import { bskyProfileToProfileView, statusToStatusView } from '#/lib/hydrate'
17
17
18
18
type Session = { did: string }
19
19
···
222
222
}
223
223
}
224
224
225
225
-
const profileView: AppBskyActorDefs.ProfileView = {
226
226
-
$type: 'app.bsky.actor.defs#profileView',
227
227
-
did: did,
228
228
-
handle: await ctx.resolver.resolveDidToHandle(did),
229
229
-
avatar: profile.avatar
230
230
-
? `https://atproto.pictures/img/${did}/${profile.avatar.ref}`
231
231
-
: undefined,
232
232
-
displayName: profile.displayName,
233
233
-
createdAt: profile.createdAt,
234
234
-
}
235
235
-
236
225
// Fetch user status
237
226
const status = await ctx.db
238
227
.selectFrom('status')
···
243
232
244
233
res.json({
245
234
did: agent.assertDid,
246
246
-
profile: profileView,
235
235
+
profile: await bskyProfileToProfileView(did, profile, ctx),
247
236
status: status ? await statusToStatusView(status, ctx) : undefined,
248
237
})
249
238
} catch (err) {