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 @@ -14,6 +14,7 @@ alertInfos: { ...state.alertInfos, [(action.payload.alertType: string)]: { + ...state.alertInfos[action.payload.alertType], totalAlerts: state.alertInfos[action.payload.alertType].totalAlerts + 1, lastAlertTime: action.payload.time, @@ -21,9 +22,19 @@ }, }; } else if (action.type === incrementColdStartCountActionType) { + const newAlertInfos = Object.fromEntries( + Object.entries(state.alertInfos).map(([alertType, info]) => [ + alertType, + { + ...info, + coldStartCount: (info.coldStartCount ?? 0) + 1, + }, + ]), + ); + return { ...state, - coldStartCount: state.coldStartCount + 1, + alertInfos: newAlertInfos, }; } 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 @@ -12,6 +12,7 @@ export type AlertInfo = { +totalAlerts: number, +lastAlertTime: number, + +coldStartCount: number, }; export type AlertInfos = { @@ -20,7 +21,6 @@ export type AlertStore = { +alertInfos: AlertInfos, - +coldStartCount: number, }; export type RecordAlertActionPayload = { @@ -31,6 +31,7 @@ const defaultAlertInfo: AlertInfo = { totalAlerts: 0, lastAlertTime: 0, + coldStartCount: 0, }; const defaultAlertInfos: AlertInfos = Object.freeze({ diff --git a/lib/utils/farcaster-utils.js b/lib/utils/farcaster-utils.js --- a/lib/utils/farcaster-utils.js +++ b/lib/utils/farcaster-utils.js @@ -9,7 +9,7 @@ import { syncedMetadataNames } from '../types/synced-metadata-types.js'; import { useSelector, useDispatch } from '../utils/redux-utils.js'; -const DISABLE_CONNECT_FARCASTER_ALERT = true; +const DISABLE_CONNECT_FARCASTER_ALERT = false; const NO_FID_METADATA = 'NONE'; function useCurrentUserFID(): ?string { 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,7 +48,6 @@ dataLoaded: false, alertStore: { alertInfos: defaultAlertInfos, - coldStartCount: 0, }, watchedThreadIDs: [], lifecycleState: 'active', diff --git a/native/account/registration/missing-registration-data/missing-registration-data-handler.react.js b/native/account/registration/missing-registration-data/missing-registration-data-handler.react.js --- a/native/account/registration/missing-registration-data/missing-registration-data-handler.react.js +++ b/native/account/registration/missing-registration-data/missing-registration-data-handler.react.js @@ -76,6 +76,7 @@ time: Date.now(), }; lastAlertInfo.current = { + ...lastAlertInfo.current, totalAlerts: lastAlertInfo.current.totalAlerts + 1, lastAlertTime: payload.time, }; diff --git a/native/components/connect-farcaster-alert-handler.react.js b/native/components/connect-farcaster-alert-handler.react.js --- a/native/components/connect-farcaster-alert-handler.react.js +++ b/native/components/connect-farcaster-alert-handler.react.js @@ -41,7 +41,8 @@ if ( !loggedIn || !isActive || - shouldSkipConnectFarcasterAlert(connectFarcasterAlertInfo, fid) + shouldSkipConnectFarcasterAlert(connectFarcasterAlertInfo, fid) || + connectFarcasterAlertInfo.coldStartCount < 2 ) { return; } diff --git a/native/components/display-community-directory-prompt.react.js b/native/components/display-community-directory-prompt.react.js --- a/native/components/display-community-directory-prompt.react.js +++ b/native/components/display-community-directory-prompt.react.js @@ -36,7 +36,6 @@ const communityInfos: CommunityInfos = useSelector( state => state.communityStore.communityInfos, ); - const coldStartCount = useSelector(state => state.alertStore.coldStartCount); const displayDirectoryPromptAlertInfo = useSelector( state => state.alertStore.alertInfos[alertTypes.DISPLAY_DIRECTORY_PROMPT], ); @@ -49,7 +48,7 @@ !isActive || fid !== null || Object.keys(communityInfos).length > 4 || - coldStartCount < 2 || + displayDirectoryPromptAlertInfo.coldStartCount < 3 || displayDirectoryPromptAlertInfo.totalAlerts > 0 || currentRoute !== HomeChatThreadListRouteName ) { 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,7 +45,6 @@ customServer: natNodeServer, alertStore: { alertInfos: defaultAlertInfos, - coldStartCount: 0, }, watchedThreadIDs: [], lifecycleState: 'active', diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -1517,6 +1517,29 @@ }, ops: {}, }): MigrationFunction<NavInfo, AppState>), + [87]: (async (state: AppState) => { + const oldAlertStore = state.alertStore; + + const newAlertInfos = Object.fromEntries( + Object.entries(oldAlertStore.alertInfos).map(([alertType, info]) => [ + alertType, + { + ...info, + coldStartCount: 0, + }, + ]), + ); + + return { + state: { + ...state, + alertStore: { + alertInfos: newAlertInfos, + }, + }, + ops: {}, + }; + }: MigrationFunction<NavInfo, AppState>), }); // NOTE: renaming this object, and especially the `version` property @@ -1527,7 +1550,7 @@ storage: AsyncStorage, blacklist: persistBlacklist, debug: __DEV__, - version: 86, + version: 87, transforms: [ messageStoreMessagesBlocklistTransform, reportStoreTransform, diff --git a/web/redux/default-state.js b/web/redux/default-state.js --- a/web/redux/default-state.js +++ b/web/redux/default-state.js @@ -46,7 +46,6 @@ dataLoaded: false, alertStore: { alertInfos: defaultAlertInfos, - coldStartCount: 0, }, watchedThreadIDs: [], lifecycleState: 'active', diff --git a/web/redux/persist-constants.js b/web/redux/persist-constants.js --- a/web/redux/persist-constants.js +++ b/web/redux/persist-constants.js @@ -3,6 +3,6 @@ const rootKey = 'root'; const rootKeyPrefix = 'persist:'; const completeRootKey = `${rootKeyPrefix}${rootKey}`; -const storeVersion = 86; +const storeVersion = 87; export { rootKey, rootKeyPrefix, completeRootKey, storeVersion }; diff --git a/web/redux/persist.js b/web/redux/persist.js --- a/web/redux/persist.js +++ b/web/redux/persist.js @@ -732,6 +732,29 @@ }, ops: {}, }): MigrationFunction<WebNavInfo, AppState>), + [87]: (async (state: AppState) => { + const oldAlertStore = state.alertStore; + + const newAlertInfos = Object.fromEntries( + Object.entries(oldAlertStore.alertInfos).map(([alertType, info]) => [ + alertType, + { + ...info, + coldStartCount: 0, + }, + ]), + ); + + return { + state: { + ...state, + alertStore: { + alertInfos: newAlertInfos, + }, + }, + ops: {}, + }; + }: MigrationFunction<WebNavInfo, AppState>), }; const persistConfig: PersistConfig = {