diff --git a/lib/actions/alert-actions.js b/lib/actions/alert-actions.js --- a/lib/actions/alert-actions.js +++ b/lib/actions/alert-actions.js @@ -1,5 +1,6 @@ // @flow const recordAlertActionType = 'RECORD_ALERT'; +const incrementColdStartCountActionType = 'INCREMENT_COLD_START_COUNT'; -export { recordAlertActionType }; +export { recordAlertActionType, incrementColdStartCountActionType }; diff --git a/lib/reducers/alert-reducer.js b/lib/reducers/alert-reducer.js --- a/lib/reducers/alert-reducer.js +++ b/lib/reducers/alert-reducer.js @@ -1,6 +1,9 @@ // @flow -import { recordAlertActionType } from '../actions/alert-actions.js'; +import { + incrementColdStartCountActionType, + recordAlertActionType, +} from '../actions/alert-actions.js'; import type { AlertStore } from '../types/alert-types.js'; import type { BaseAction } from '../types/redux-types'; @@ -17,6 +20,11 @@ }, }, }; + } else if (action.type === incrementColdStartCountActionType) { + return { + ...state, + coldStartCount: state.coldStartCount + 1, + }; } return state; diff --git a/lib/types/alert-types.js b/lib/types/alert-types.js --- a/lib/types/alert-types.js +++ b/lib/types/alert-types.js @@ -19,6 +19,7 @@ export type AlertStore = { +alertInfos: AlertInfos, + +coldStartCount: number, }; export type RecordAlertActionPayload = { diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -1147,6 +1147,10 @@ +type: 'RECORD_ALERT', +payload: RecordAlertActionPayload, } + | { + +type: 'INCREMENT_COLD_START_COUNT', + +payload: void, + } | { +type: 'UPDATE_USER_AVATAR_STARTED', +payload: UpdateUserAvatarRequest, diff --git a/lib/utils/reducers-utils.test.js b/lib/utils/reducers-utils.test.js --- a/lib/utils/reducers-utils.test.js +++ b/lib/utils/reducers-utils.test.js @@ -48,6 +48,7 @@ dataLoaded: false, alertStore: { alertInfos: defaultAlertInfos, + coldStartCount: 0, }, watchedThreadIDs: [], lifecycleState: 'active', diff --git a/native/components/cold-start-tracker.react.js b/native/components/cold-start-tracker.react.js new file mode 100644 --- /dev/null +++ b/native/components/cold-start-tracker.react.js @@ -0,0 +1,33 @@ +// @flow + +import * as React from 'react'; + +import { incrementColdStartCountActionType } from 'lib/actions/alert-actions.js'; +import { useIsLoggedInToIdentityAndAuthoritativeKeyserver } from 'lib/hooks/account-hooks.js'; +import { useDispatch } from 'lib/utils/redux-utils.js'; + +import { useSelector } from '../redux/redux-utils.js'; + +function ColdStartTracker(): React.Node { + const dispatch = useDispatch(); + const loggedIn = useIsLoggedInToIdentityAndAuthoritativeKeyserver(); + const isActive = useSelector(state => state.lifecycleState !== 'background'); + + const hasTrackedColdStartRef = React.useRef(false); + + React.useEffect(() => { + if (!loggedIn || !isActive || hasTrackedColdStartRef.current) { + return; + } + + hasTrackedColdStartRef.current = true; + + dispatch({ + type: incrementColdStartCountActionType, + }); + }, [dispatch, loggedIn, isActive]); + + return null; +} + +export default ColdStartTracker; diff --git a/native/redux/default-state.js b/native/redux/default-state.js --- a/native/redux/default-state.js +++ b/native/redux/default-state.js @@ -45,6 +45,7 @@ customServer: natNodeServer, alertStore: { alertInfos: defaultAlertInfos, + coldStartCount: 0, }, watchedThreadIDs: [], lifecycleState: 'active', diff --git a/native/root.react.js b/native/root.react.js --- a/native/root.react.js +++ b/native/root.react.js @@ -59,6 +59,7 @@ import AccessTokenHandler from './components/access-token-handler.react.js'; import { AutoJoinCommunityHandler } from './components/auto-join-community-handler.react.js'; import BackgroundIdentityLoginHandler from './components/background-identity-login-handler.react.js'; +import ColdStartTracker from './components/cold-start-tracker.react.js'; import ConnectFarcasterAlertHandler from './components/connect-farcaster-alert-handler.react.js'; import DMActivityHandler from './components/dm-activity-handler.react.js'; import { FeatureFlagsProvider } from './components/feature-flags-provider.react.js'; @@ -385,6 +386,7 @@ {gated} +