Skip to content

Commit

Permalink
[lib] refactor fetchFollowedFarcasterChannels
Browse files Browse the repository at this point in the history
Summary: small refactor so that I can reuse code in next diff when I introduce fetchLedFarcasterChannels method

Test Plan: tested with next diff

Reviewers: ashoat

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D13293
  • Loading branch information
vdhanan committed Sep 11, 2024
1 parent 7488a4e commit ad10638
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/utils/neynar-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ class NeynarClient {
return fids;
}

async fetchFollowedFarcasterChannels(fid: string): Promise<NeynarChannel[]> {
async fetchFollowedFarcasterChannelsWithFilter(
fid: string,
filterFn: (channel: NeynarChannel) => boolean,
): Promise<NeynarChannel[]> {
const farcasterChannels = [];
let paginationCursor = null;

Expand All @@ -144,7 +147,9 @@ class NeynarClient {
const { channels, next } = json;

channels.forEach(channel => {
farcasterChannels.push(channel);
if (filterFn(channel)) {
farcasterChannels.push(channel);
}
});

paginationCursor = next.cursor;
Expand All @@ -160,6 +165,10 @@ class NeynarClient {
return farcasterChannels;
}

fetchFollowedFarcasterChannels(fid: string): Promise<NeynarChannel[]> {
return this.fetchFollowedFarcasterChannelsWithFilter(fid, () => true);
}

async fetchFarcasterChannelByName(
channelName: string,
): Promise<?NeynarChannel> {
Expand Down

0 comments on commit ad10638

Please sign in to comment.