Skip to content

Commit 5165db2

Browse files
chore: minor changes in profile function
1 parent d5d3815 commit 5165db2

3 files changed

Lines changed: 28 additions & 9 deletions

File tree

packages/client/src/actor/actor.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,29 @@ export class Actor {
156156
}
157157
}
158158

159+
// TODO: we can give this a better name
160+
export class ActorWithProfileFunction extends Actor {
161+
async profile() {
162+
const data = await this.client
163+
.get('app.bsky.actor.getProfile', {
164+
params: { actor: this.did },
165+
})
166+
.then((res) => res.data);
167+
168+
if (
169+
data.viewer?.knownFollowers?.followers &&
170+
data.viewer?.knownFollowers?.followers.length > 0
171+
) {
172+
data.viewer.knownFollowers.followers =
173+
data.viewer.knownFollowers.followers.map(
174+
(follower) => new BasicActorProfile(this.client, follower),
175+
);
176+
}
177+
178+
return data;
179+
}
180+
}
181+
159182
export class BasicActorProfile
160183
extends Actor
161184
implements AppBskyActorDefs.ProfileViewBasic

packages/client/src/agent/agent.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
At,
66
Queries,
77
} from '@tsky/lexicons';
8-
import { DetailedActorProfile } from '~/actor';
8+
import { ActorWithProfileFunction } from '~/actor';
99
import { Feed } from '~/feed';
1010
import { List } from '~/list';
1111
import { Search } from '~/search';
@@ -30,12 +30,8 @@ export class Agent {
3030
/**
3131
* Get detailed profile view of an actor. Does not require auth, but contains relevant metadata with auth.
3232
*/
33-
async actor(identifier: At.DID | At.Handle): Promise<DetailedActorProfile> {
34-
const res = await this.client.get('app.bsky.actor.getProfile', {
35-
params: { actor: identifier },
36-
});
37-
38-
return new DetailedActorProfile(this.client, res.data);
33+
async actor(identifier: At.DID): Promise<ActorWithProfileFunction> {
34+
return new ActorWithProfileFunction(this.client, identifier);
3935
}
4036

4137
list(uri: string) {

packages/client/src/user/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { AppBskyFeedGetTimeline } from '@tsky/lexicons';
2-
import { Actor } from '~/actor';
2+
import { ActorWithProfileFunction } from '~/actor';
33
import type { RPCOptions } from '~/types';
44
import { Paginator } from '~/utils';
55
import { Mute } from './mute';
@@ -8,7 +8,7 @@ import { Preferences } from './preferences';
88
import { Suggestion } from './suggestion';
99
import { Unmute } from './unmute';
1010

11-
export class User extends Actor {
11+
export class User extends ActorWithProfileFunction {
1212
get preferences() {
1313
return new Preferences(this.client);
1414
}

0 commit comments

Comments
 (0)