diff --git a/lib/components/farcaster-data-handler.react.js b/lib/components/farcaster-data-handler.react.js --- a/lib/components/farcaster-data-handler.react.js +++ b/lib/components/farcaster-data-handler.react.js @@ -26,6 +26,8 @@ const hasUserCookie = !!(cookie && cookie.startsWith('user=')); const loggedIn = hasCurrentUserInfo && hasUserCookie; + const currentUserID = useSelector(state => state.currentUserInfo?.id); + const neynarClient = React.useContext(NeynarClientContext)?.client; const identityServiceClient = React.useContext(IdentityClientContext); @@ -37,10 +39,10 @@ serverUpdateRelationships, ); const createThreadsAndRobotextForFarcasterMutuals = React.useCallback( - (userIDs: $ReadOnlyArray) => + (userIDsToFID: { +[userID: string]: string }) => updateRelationships({ action: relationshipActions.FARCASTER_MUTUAL, - userIDs, + userIDsToFID, }), [updateRelationships], ); @@ -61,7 +63,14 @@ } prevCanQueryRef.current = canQuery; - if (!loggedIn || !isActive || !fid || !neynarClient || !getFarcasterUsers) { + if ( + !loggedIn || + !isActive || + !fid || + !neynarClient || + !getFarcasterUsers || + !currentUserID + ) { return; } @@ -70,16 +79,28 @@ const commFCUsers = await getFarcasterUsers(followerFIDs); - const commUserIDs = commFCUsers.map(({ userID }) => userID); + const newCommUsers = commFCUsers.filter( + ({ userID }) => !userInfos[userID], + ); - const newCommUserIDs = commUserIDs.filter(userID => !userInfos[userID]); - if (newCommUserIDs.length === 0) { + if (newCommUsers.length === 0) { return; } + const userIDsToFID: { +[userID: string]: string } = Object.fromEntries( + newCommUsers.map(({ userID, farcasterID }) => [userID, farcasterID]), + ); + + const userIDsToFIDIncludingCurrentUser: { +[userID: string]: string } = { + ...userIDsToFID, + [(currentUserID: string)]: fid, + }; + void dispatchActionPromise( updateRelationshipsActionTypes, - createThreadsAndRobotextForFarcasterMutuals(newCommUserIDs), + createThreadsAndRobotextForFarcasterMutuals( + userIDsToFIDIncludingCurrentUser, + ), ); })(); }, [ @@ -91,6 +112,7 @@ userInfos, dispatchActionPromise, createThreadsAndRobotextForFarcasterMutuals, + currentUserID, ]); return null;