11import type {
22 AppBskyActorDefs ,
33 AppBskyFeedGetAuthorFeed ,
4+ AppBskyGraphDefs ,
5+ At ,
6+ ComAtprotoLabelDefs ,
7+ ComAtprotoRepoStrongRef ,
48} from '@tsky/lexicons' ;
59import type { Client } from '~/agent/client' ;
10+ import { List } from '~/list' ;
611import type { RPCOptions } from '~/types' ;
712import { Paginator } from '~/utils' ;
813
914export class Actor {
1015 client : Client ;
11- identifier : string ;
16+ did : At . DID ;
1217
13- constructor ( client : Client , identifier : string ) {
18+ constructor ( client : Client , did : At . DID ) {
1419 this . client = client ;
15- this . identifier = identifier ;
16- }
17-
18- /**
19- * Get detailed profile view of an actor. Does not require auth, but contains relevant metadata with auth.
20- */
21- async profile ( ) : Promise < AppBskyActorDefs . ProfileViewDetailed > {
22- const res = await this . client . get ( 'app.bsky.actor.getProfile' , {
23- params : { actor : this . identifier } ,
24- } ) ;
25-
26- return res . data ;
20+ this . did = did ;
2721 }
2822
2923 /**
@@ -32,7 +26,7 @@ export class Actor {
3226 starterPacks ( limit ?: number , options : RPCOptions = { } ) {
3327 return Paginator . init ( async ( cursor ) => {
3428 const res = await this . client . get ( 'app.bsky.graph.getActorStarterPacks' , {
35- params : { cursor, actor : this . identifier , limit } ,
29+ params : { cursor, actor : this . did , limit } ,
3630 ...options ,
3731 } ) ;
3832
@@ -48,13 +42,19 @@ export class Actor {
4842 const res = await this . client . get ( 'app.bsky.graph.getFollowers' , {
4943 params : {
5044 cursor,
51- actor : this . identifier ,
45+ actor : this . did ,
5246 limit,
5347 } ,
5448 ...options ,
5549 } ) ;
5650
57- return res . data ;
51+ return {
52+ ...res . data ,
53+ subject : new ActorProfile ( this . client , res . data . subject ) ,
54+ followers : res . data . followers . map (
55+ ( follower ) => new ActorProfile ( this . client , follower ) ,
56+ ) ,
57+ } ;
5858 } ) ;
5959 }
6060
@@ -66,13 +66,19 @@ export class Actor {
6666 const res = await this . client . get ( 'app.bsky.graph.getFollows' , {
6767 params : {
6868 cursor,
69- actor : this . identifier ,
69+ actor : this . did ,
7070 limit,
7171 } ,
7272 ...options ,
7373 } ) ;
7474
75- return res . data ;
75+ return {
76+ ...res . data ,
77+ subject : new ActorProfile ( this . client , res . data . subject ) ,
78+ follows : res . data . follows . map (
79+ ( follow ) => new ActorProfile ( this . client , follow ) ,
80+ ) ,
81+ } ;
7682 } ) ;
7783 }
7884
@@ -84,13 +90,17 @@ export class Actor {
8490 const res = await this . client . get ( 'app.bsky.graph.getLists' , {
8591 params : {
8692 cursor,
87- actor : this . identifier ,
93+ actor : this . did ,
8894 limit,
8995 } ,
9096 ...options ,
9197 } ) ;
9298
93- return res . data ;
99+ return {
100+ ...res . data ,
101+ // TODO: Solve this
102+ // lists: res.data.lists.map((list) => new List(this.client, list)),
103+ } ;
94104 } ) ;
95105 }
96106
@@ -100,13 +110,18 @@ export class Actor {
100110 async relationships ( others ?: string [ ] , options ?: RPCOptions ) {
101111 const res = await this . client . get ( 'app.bsky.graph.getRelationships' , {
102112 params : {
103- actor : this . identifier ,
113+ actor : this . did ,
104114 others,
105115 } ,
106116 ...options ,
107117 } ) ;
108118
109- return res . data ;
119+ return {
120+ ...res . data ,
121+ actor : res . data . actor
122+ ? new Actor ( this . client , res . data . actor )
123+ : undefined ,
124+ } ;
110125 }
111126
112127 /**
@@ -115,7 +130,7 @@ export class Actor {
115130 feeds ( limit ?: number , options ?: RPCOptions ) {
116131 return Paginator . init ( async ( cursor ) => {
117132 const res = await this . client . get ( 'app.bsky.feed.getActorFeeds' , {
118- params : { cursor, actor : this . identifier , limit } ,
133+ params : { cursor, actor : this . did , limit } ,
119134 ...options ,
120135 } ) ;
121136
@@ -132,11 +147,61 @@ export class Actor {
132147 ) {
133148 return Paginator . init ( async ( cursor ) => {
134149 const res = await this . client . get ( 'app.bsky.feed.getAuthorFeed' , {
135- params : { cursor, ...params , actor : this . identifier } ,
150+ params : { cursor, ...params , actor : this . did } ,
136151 ...options ,
137152 } ) ;
138153
139154 return res . data ;
140155 } ) ;
141156 }
142157}
158+
159+ export class BasicActorProfile
160+ extends Actor
161+ implements AppBskyActorDefs . ProfileViewBasic
162+ {
163+ // @ts -expect-error - We added this property with Object.assign
164+ handle : string ;
165+ associated ?: AppBskyActorDefs . ProfileAssociated ;
166+ avatar ?: string ;
167+ createdAt ?: string ;
168+ displayName ?: string ;
169+ labels ?: ComAtprotoLabelDefs . Label [ ] ;
170+ viewer ?: AppBskyActorDefs . ViewerState ;
171+ $type ?: string ;
172+
173+ constructor ( client : Client , actor : AppBskyActorDefs . ProfileViewBasic ) {
174+ super ( client , actor . did ) ;
175+ Object . assign ( this , actor ) ;
176+ }
177+ }
178+
179+ export class ActorProfile
180+ extends BasicActorProfile
181+ implements AppBskyActorDefs . ProfileView
182+ {
183+ description ?: string ;
184+ indexedAt ?: string ;
185+
186+ constructor ( client : Client , actor : AppBskyActorDefs . ProfileViewDetailed ) {
187+ super ( client , actor ) ;
188+ Object . assign ( this , actor ) ;
189+ }
190+ }
191+
192+ export class DetailedActorProfile
193+ extends ActorProfile
194+ implements AppBskyActorDefs . ProfileViewDetailed
195+ {
196+ banner ?: string ;
197+ followersCount ?: number ;
198+ followsCount ?: number ;
199+ joinedViaStarterPack ?: AppBskyGraphDefs . StarterPackViewBasic ;
200+ pinnedPost ?: ComAtprotoRepoStrongRef . Main ;
201+ postsCount ?: number ;
202+
203+ constructor ( client : Client , actor : AppBskyActorDefs . ProfileViewDetailed ) {
204+ super ( client , actor ) ;
205+ Object . assign ( this , actor ) ;
206+ }
207+ }
0 commit comments