diff --git a/lib/shared/farcaster/farcaster-hooks.js b/lib/shared/farcaster/farcaster-hooks.js --- a/lib/shared/farcaster/farcaster-hooks.js +++ b/lib/shared/farcaster/farcaster-hooks.js @@ -1036,6 +1036,36 @@ ]); } +function useLightweightSyncOnAppStart() { + const isUserLoggedIn = useSelector(isLoggedIn); + const userDataReady = useIsUserDataReady(); + const fullyLoggedIn = isUserLoggedIn && userDataReady; + const currentUserSupportsDCs = useCurrentUserSupportsDCs(); + const farcasterDCsLoaded = useFarcasterDCsLoaded(); + const lightweightSync = useLightweightFarcasterConversationsSync(); + const started = React.useRef(false); + + React.useEffect(() => { + // We're waiting for the state to be ready + if (started.current || !fullyLoggedIn || !currentUserSupportsDCs) { + return; + } + started.current = true; + // If we're here, it means that the full sync is not yet done. In that + // case, we don't want to perform the lightweight sync during this run + // of the app. + if (!farcasterDCsLoaded) { + return; + } + void lightweightSync(); + }, [ + currentUserSupportsDCs, + farcasterDCsLoaded, + fullyLoggedIn, + lightweightSync, + ]); +} + export { useFarcasterConversationsSync, useLightweightFarcasterConversationsSync, @@ -1047,4 +1077,5 @@ useAddNewFarcasterMessage, useFarcasterSync, useFarcasterThreadRefresher, + useLightweightSyncOnAppStart, }; diff --git a/native/components/farcaster-sync-handler.react.js b/native/components/farcaster-sync-handler.react.js --- a/native/components/farcaster-sync-handler.react.js +++ b/native/components/farcaster-sync-handler.react.js @@ -5,6 +5,7 @@ import { useIsUserDataReady } from 'lib/hooks/backup-hooks.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; +import { useLightweightSyncOnAppStart } from 'lib/shared/farcaster/farcaster-hooks.js'; import { useCurrentUserSupportsDCs, useFarcasterDCsLoaded, @@ -26,6 +27,8 @@ const farcasterDCsLoaded = useFarcasterDCsLoaded(); const currentRouteName = useCurrentLeafRouteName(); + useLightweightSyncOnAppStart(); + React.useEffect(() => { if (!navContext) { return; diff --git a/web/components/farcaster-sync-overlay.react.js b/web/components/farcaster-sync-overlay.react.js --- a/web/components/farcaster-sync-overlay.react.js +++ b/web/components/farcaster-sync-overlay.react.js @@ -2,6 +2,7 @@ import * as React from 'react'; +import { useLightweightSyncOnAppStart } from 'lib/shared/farcaster/farcaster-hooks.js'; import { useCurrentUserSupportsDCs, useFarcasterDCsLoaded, @@ -21,6 +22,8 @@ const isFullSyncInProgress = currentUserSupportsDCs && farcasterDCsLoaded === false; + useLightweightSyncOnAppStart(); + const style = React.useMemo(() => { if (!isFullSyncInProgress) { return {};