From ad1063878f4a91d06333126c06f44e12f18a3f5a Mon Sep 17 00:00:00 2001 From: Varun Dhananjaya Date: Wed, 11 Sep 2024 19:41:56 +0200 Subject: [PATCH] [lib] refactor fetchFollowedFarcasterChannels 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 --- lib/utils/neynar-client.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/utils/neynar-client.js b/lib/utils/neynar-client.js index 4ff41da0b3..eb4b877c8f 100644 --- a/lib/utils/neynar-client.js +++ b/lib/utils/neynar-client.js @@ -117,7 +117,10 @@ class NeynarClient { return fids; } - async fetchFollowedFarcasterChannels(fid: string): Promise { + async fetchFollowedFarcasterChannelsWithFilter( + fid: string, + filterFn: (channel: NeynarChannel) => boolean, + ): Promise { const farcasterChannels = []; let paginationCursor = null; @@ -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; @@ -160,6 +165,10 @@ class NeynarClient { return farcasterChannels; } + fetchFollowedFarcasterChannels(fid: string): Promise { + return this.fetchFollowedFarcasterChannelsWithFilter(fid, () => true); + } + async fetchFarcasterChannelByName( channelName: string, ): Promise {