Page MenuHomePhabricator

D13613.id44915.diff
No OneTemporary

D13613.id44915.diff

diff --git a/keyserver/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js
--- a/keyserver/src/updaters/thread-updaters.js
+++ b/keyserver/src/updaters/thread-updaters.js
@@ -942,13 +942,12 @@
return null;
}
- const ledChannels =
- await neynarClient?.fetchLedFarcasterChannels(farcasterID);
+ const userLeadsChannel = await neynarClient?.userLeadsChannel(
+ farcasterID,
+ communityFarcasterChannelTag,
+ );
- if (
- !ledChannels ||
- !ledChannels.some(channel => channel.id === communityFarcasterChannelTag)
- ) {
+ if (!userLeadsChannel) {
return null;
}
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
@@ -4,6 +4,7 @@
import { getMessageForException } from './errors.js';
import type { NeynarChannel, NeynarUser } from '../types/farcaster-types.js';
+import sleep from '../utils/sleep.js';
type FetchRelevantFollowersResponse = {
+all_relevant_followers_dehydrated: $ReadOnlyArray<{
@@ -69,7 +70,7 @@
>;
cacheTTL: number;
- constructor(apiKey: string, cacheTTL: number = 60000) {
+ constructor(apiKey: string, cacheTTL: number = 600000) {
this.apiKey = apiKey;
this.ledChannelsCache = new Map();
this.cacheTTL = cacheTTL; // Default TTL of 60 seconds
@@ -225,6 +226,30 @@
}
}
+ async userLeadsChannel(
+ fid: string,
+ farcasterChannelID: string,
+ ): Promise<boolean> {
+ const userChannelsPromise = (async () => {
+ const ledChannels = await this.fetchLedFarcasterChannels(fid);
+ return ledChannels.some(channel => channel.id === farcasterChannelID);
+ })();
+
+ const channelSearchPromise = (async () => {
+ try {
+ const channel =
+ await this.fetchFarcasterChannelByName(farcasterChannelID);
+ return channel?.lead.fid === parseInt(fid);
+ } catch (e) {
+ // Wait 5 seconds to give the other promise a chance to settle
+ await sleep(5000);
+ throw e;
+ }
+ })();
+
+ return Promise.race([userChannelsPromise, channelSearchPromise]);
+ }
+
async getFarcasterUsers(
fids: $ReadOnlyArray<string>,
): Promise<Array<?FarcasterUser>> {

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 20, 3:39 AM (22 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2540901
Default Alt Text
D13613.id44915.diff (2 KB)

Event Timeline