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 @@ -7,11 +7,13 @@ updateRelationships as serverUpdateRelationships, updateRelationshipsActionTypes, } from '../actions/relationship-actions.js'; +import { setSyncedMetadataEntryActionType } from '../actions/synced-metadata-actions.js'; import { NeynarClientContext } from '../components/neynar-client-provider.react.js'; import { useLegacyAshoatKeyserverCall } from '../keyserver-conn/legacy-keyserver-call.js'; import { isLoggedInToIdentityAndAuthoritativeKeyserver } from '../selectors/user-selectors.js'; import { IdentityClientContext } from '../shared/identity-client-context.js'; import { relationshipActions } from '../types/relationship-types.js'; +import { syncedMetadataNames } from '../types/synced-metadata-types.js'; import { useCurrentUserFID } from '../utils/farcaster-utils.js'; import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; import { useSelector, useDispatch } from '../utils/redux-utils.js'; @@ -132,6 +134,45 @@ }); }, [loggedIn, isActive, findUserIdentities, userInfos, dispatch]); + const prevCanQueryHandleCurrentUserFIDRef = React.useRef(); + const canQueryHandleCurrentUserFID = isActive && !fid && loggedIn; + + const handleCurrentUserFID = React.useCallback(async () => { + if ( + canQueryHandleCurrentUserFID === + prevCanQueryHandleCurrentUserFIDRef.current + ) { + return; + } + prevCanQueryHandleCurrentUserFIDRef.current = canQueryHandleCurrentUserFID; + + if ( + !canQueryHandleCurrentUserFID || + !findUserIdentities || + !currentUserID + ) { + return; + } + + const currentUserIdentityObj = await findUserIdentities([currentUserID]); + const identityFID = currentUserIdentityObj[currentUserID]?.farcasterID; + + if (identityFID) { + dispatch({ + type: setSyncedMetadataEntryActionType, + payload: { + name: syncedMetadataNames.CURRENT_USER_FID, + data: identityFID, + }, + }); + } + }, [ + canQueryHandleCurrentUserFID, + findUserIdentities, + currentUserID, + dispatch, + ]); + React.useEffect(() => { if (!usingCommServicesAccessToken) { return; @@ -139,7 +180,8 @@ void handleFarcasterMutuals(); void handleUserStoreFIDs(); - }, [handleFarcasterMutuals, handleUserStoreFIDs]); + void handleCurrentUserFID(); + }, [handleCurrentUserFID, handleFarcasterMutuals, handleUserStoreFIDs]); return null; } diff --git a/web/app.react.js b/web/app.react.js --- a/web/app.react.js +++ b/web/app.react.js @@ -15,6 +15,7 @@ } from 'lib/actions/entry-actions.js'; import { ChatMentionContextProvider } from 'lib/components/chat-mention-provider.react.js'; import { EditUserAvatarProvider } from 'lib/components/edit-user-avatar-provider.react.js'; +import { FarcasterDataHandler } from 'lib/components/farcaster-data-handler.react.js'; import { ModalProvider, useModalContext, @@ -250,6 +251,7 @@ + {content}