Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3358201
D13530.id44702.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13530.id44702.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
@@ -3,19 +3,17 @@
import invariant from 'invariant';
import { getMessageForException } from './errors.js';
-import type {
- NeynarChannel,
- NeynarUser,
- NeynarUserWithViewerContext,
-} from '../types/farcaster-types.js';
-
-type FetchFollowersResponse = {
- +result: {
- +users: $ReadOnlyArray<NeynarUserWithViewerContext>,
- +next: {
- +cursor: ?string,
+import type { NeynarChannel, NeynarUser } from '../types/farcaster-types.js';
+
+type FetchRelevantFollowersResponse = {
+ +all_relevant_followers_dehydrated: $ReadOnlyArray<{
+ user: {
+ fid: number,
+ ...
},
- },
+ ...
+ }>,
+ ...
};
type FetchFarcasterChannelsResponse = {
@@ -60,7 +58,6 @@
return `${neynarURL}${apiCall}?${new URLSearchParams(params).toString()}`;
}
-const fetchFollowerLimit = 150;
const fetchFollowedChannelsLimit = 100;
const fetchChannelsLimit = 50;
@@ -73,48 +70,35 @@
// We're using the term "friend" for a bidirectional follow
async fetchFriendFIDs(fid: string): Promise<string[]> {
- const fids = [];
- let paginationCursor = null;
-
- do {
- const params: { [string]: string } = {
- fid,
- viewerFid: fid,
- limit: fetchFollowerLimit.toString(),
- ...(paginationCursor ? { cursor: paginationCursor } : null),
- };
-
- const url = getNeynarURL('1', 'followers', params);
-
- try {
- const response = await fetch(url, {
- method: 'GET',
- headers: {
- Accept: 'application/json',
- api_key: this.apiKey,
- },
- });
+ const params: { [string]: string } = {
+ target_fid: fid,
+ viewer_fid: fid,
+ };
- const json: FetchFollowersResponse = await response.json();
- const { users } = json.result;
+ const url = getNeynarURL('2', 'followers/relevant', params);
- for (const user of users) {
- if (user.viewerContext.following) {
- fids.push(user.fid.toString());
- }
- }
+ try {
+ const response = await fetch(url, {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ api_key: this.apiKey,
+ },
+ });
- paginationCursor = json.result.next.cursor;
- } catch (error) {
- console.log(
- 'Failed to fetch friend FIDs:',
- getMessageForException(error) ?? 'unknown',
- );
- throw error;
- }
- } while (paginationCursor);
+ const json: FetchRelevantFollowersResponse = await response.json();
+ const { all_relevant_followers_dehydrated } = json;
- return fids;
+ 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;
+ }
}
async fetchFollowedFarcasterChannelsWithFilter(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 3:38 AM (19 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2578220
Default Alt Text
D13530.id44702.diff (3 KB)
Attached To
Mode
D13530: [lib] use v2 relevant followers API to find farcaster friends
Attached
Detach File
Event Timeline
Log In to Comment