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,10 @@ const hasUserCookie = !!(cookie && cookie.startsWith('user=')); const loggedIn = hasCurrentUserInfo && hasUserCookie; + const currentUserID = useSelector( + state => state.currentUserInfo && state.currentUserInfo.id, + ); + const neynarClient = React.useContext(NeynarClientContext)?.client; const identityServiceClient = React.useContext(IdentityClientContext); @@ -37,10 +41,10 @@ serverUpdateRelationships, ); const createThreadsAndRobotextForFarcasterMutuals = React.useCallback( - (userIDs: $ReadOnlyArray) => + (userIDsToFID: { +[userID: string]: string }) => updateRelationships({ action: relationshipActions.FARCASTER_MUTUAL, - userIDs, + userIDsToFID, }), [updateRelationships], ); @@ -61,7 +65,14 @@ } prevCanQueryRef.current = canQuery; - if (!loggedIn || !isActive || !fid || !neynarClient || !getFarcasterUsers) { + if ( + !loggedIn || + !isActive || + !fid || + !neynarClient || + !getFarcasterUsers || + !currentUserID + ) { return; } @@ -70,16 +81,32 @@ 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 } = newCommUsers.reduce( + (acc: { [userID: string]: string }, { userID, farcasterID }) => { + acc[userID] = farcasterID; + return acc; + }, + {}, + ); + + const userIDsToFIDIncludingCurrentUser: { +[userID: string]: string } = { + ...userIDsToFID, + [(currentUserID: string)]: fid, + }; + void dispatchActionPromise( updateRelationshipsActionTypes, - createThreadsAndRobotextForFarcasterMutuals(newCommUserIDs), + createThreadsAndRobotextForFarcasterMutuals( + userIDsToFIDIncludingCurrentUser, + ), ); })(); }, [ @@ -91,6 +118,7 @@ userInfos, dispatchActionPromise, createThreadsAndRobotextForFarcasterMutuals, + currentUserID, ]); return null;