Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32204580
D15218.1765116010.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D15218.1765116010.diff
View Options
diff --git a/lib/utils/neynar-client.js b/lib/utils/neynar-client.js
--- a/lib/utils/neynar-client.js
+++ b/lib/utils/neynar-client.js
@@ -10,14 +10,17 @@
NeynarPostCastResponse,
} from '../types/farcaster-types.js';
-type FetchRelevantFollowersResponse = {
- +all_relevant_followers_dehydrated: $ReadOnlyArray<{
+type FetchReciprocalFollowersResponse = {
+ +users: $ReadOnlyArray<{
+user: {
+fid: number,
...
},
...
}>,
+ +next: {
+ +cursor: ?string,
+ },
...
};
@@ -69,6 +72,7 @@
}
const fetchFollowedChannelsLimit = 100;
+const fetchFriendsLimit = 100;
const fetchChannelsLimit = 50;
class NeynarClient {
@@ -80,35 +84,45 @@
// We're using the term "friend" for a bidirectional follow
async fetchFriendFIDs(fid: string): Promise<string[]> {
- const params: { [string]: string } = {
- target_fid: fid,
- viewer_fid: fid,
- };
+ const fids = [];
+ let paginationCursor = null;
- const url = getNeynarURL('2', 'followers/relevant', params);
+ do {
+ const params: { [string]: string } = {
+ fid,
+ limit: fetchFriendsLimit.toString(),
+ ...(paginationCursor ? { cursor: paginationCursor } : null),
+ };
- try {
- const response = await fetch(url, {
- method: 'GET',
- headers: {
- Accept: 'application/json',
- api_key: this.apiKey,
- },
- });
+ const url = getNeynarURL('2', 'followers/reciprocal', params);
+
+ try {
+ const response = await fetch(url, {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ api_key: this.apiKey,
+ },
+ });
- const json: FetchRelevantFollowersResponse = await response.json();
- const { all_relevant_followers_dehydrated } = json;
+ const json: FetchReciprocalFollowersResponse = await response.json();
+ const { users, next } = json;
- return all_relevant_followers_dehydrated.map(follower =>
- follower.user.fid.toString(),
- );
- } catch (error) {
- console.log(
- 'Failed to fetch friend FIDs:',
- getMessageForException(error) ?? 'unknown',
- );
- throw error;
- }
+ users.forEach(follower => {
+ fids.push(follower.user.fid.toString());
+ });
+
+ paginationCursor = next.cursor;
+ } catch (error) {
+ console.log(
+ 'Failed to fetch friend FIDs:',
+ getMessageForException(error) ?? 'unknown',
+ );
+ throw error;
+ }
+ } while (paginationCursor);
+
+ return fids;
}
async fetchFollowedFarcasterChannels(fid: string): Promise<NeynarChannel[]> {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 7, 2:00 PM (15 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5844436
Default Alt Text
D15218.1765116010.diff (2 KB)
Attached To
Mode
D15218: [lib] Fix NeynarClient.fetchFriendFIDs
Attached
Detach File
Event Timeline
Log In to Comment