Retro Bulletin Board Systems on atproto. Web app and TUI.
lazy mirror of alyraffauf/atbbs
atbbs.xyz
forums
python
tui
atproto
bbs
1/** Fetch a user's atbbs profile and BBS info. */
2
3import { getAvatar, getRecord, resolveIdentity } from "./atproto";
4import { PROFILE, SITE } from "./lexicon";
5import { isProfileRecord, isSiteRecord } from "./recordGuards";
6
7export interface Profile {
8 did: string;
9 handle: string;
10 pdsUrl: string;
11 avatar?: string;
12 name?: string;
13 pronouns?: string;
14 bio?: string;
15 bbsName?: string;
16 bbsDescription?: string;
17 createdAt?: string;
18}
19
20export async function fetchProfile(handle: string): Promise<Profile | null> {
21 let identity;
22 try {
23 identity = await resolveIdentity(handle);
24 } catch {
25 return null;
26 }
27
28 const [[profileResult, siteResult], avatar] = await Promise.all([
29 Promise.allSettled([
30 getRecord(identity.did, PROFILE, "self"),
31 getRecord(identity.did, SITE, "self"),
32 ]),
33 getAvatar(identity.did),
34 ]);
35
36 const profile: Profile = {
37 did: identity.did,
38 handle: identity.handle,
39 pdsUrl: identity.pds ?? "",
40 avatar,
41 };
42
43 if (
44 profileResult.status === "fulfilled" &&
45 isProfileRecord(profileResult.value)
46 ) {
47 const value = profileResult.value.value;
48 profile.name = value.name;
49 profile.pronouns = value.pronouns;
50 profile.bio = value.bio;
51 profile.createdAt = value.createdAt;
52 }
53
54 if (
55 siteResult.status === "fulfilled" &&
56 isSiteRecord(siteResult.value)
57 ) {
58 const value = siteResult.value.value;
59 profile.bbsName = value.name;
60 profile.bbsDescription = value.description;
61 }
62
63 return profile;
64}