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 @@ -9,7 +9,6 @@ import { FIDContext } from '../components/fid-provider.react.js'; import { NeynarClientContext } from '../components/neynar-client-provider.react.js'; import { cookieSelector } from '../selectors/keyserver-selectors.js'; -import { isLoggedIn } from '../selectors/user-selectors.js'; import { IdentityClientContext } from '../shared/identity-client-context.js'; import { relationshipActions } from '../types/relationship-types.js'; import { useLegacyAshoatKeyserverCall } from '../utils/action-utils.js'; @@ -21,10 +20,10 @@ function FarcasterDataHandler(): React.Node { const isActive = useSelector(state => state.lifecycleState !== 'background'); - const hasCurrentUserInfo = useSelector(isLoggedIn); const cookie = useSelector(cookieSelector(authoritativeKeyserverID())); const hasUserCookie = !!(cookie && cookie.startsWith('user=')); - const loggedIn = hasCurrentUserInfo && hasUserCookie; + const currentUserID = useSelector(state => state.currentUserInfo?.id); + const loggedIn = !!currentUserID && hasUserCookie; const neynarClient = React.useContext(NeynarClientContext)?.client; @@ -37,10 +36,10 @@ serverUpdateRelationships, ); const createThreadsAndRobotextForFarcasterMutuals = React.useCallback( - (userIDs: $ReadOnlyArray) => + (userIDsToFID: { +[userID: string]: string }) => updateRelationships({ action: relationshipActions.FARCASTER_MUTUAL, - userIDs, + userIDsToFID, }), [updateRelationships], ); @@ -61,7 +60,14 @@ } prevCanQueryRef.current = canQuery; - if (!loggedIn || !isActive || !fid || !neynarClient || !getFarcasterUsers) { + if ( + !loggedIn || + !isActive || + !fid || + !neynarClient || + !getFarcasterUsers || + !currentUserID + ) { return; } @@ -70,16 +76,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 +109,7 @@ userInfos, dispatchActionPromise, createThreadsAndRobotextForFarcasterMutuals, + currentUserID, ]); return null;