diff --git a/lib/reducers/alert-reducer.js b/lib/reducers/alert-reducer.js new file mode 100644 --- /dev/null +++ b/lib/reducers/alert-reducer.js @@ -0,0 +1,24 @@ +// @flow + +import { alertTypes, type AlertStore } from '../types/alert-types.js'; +import type { BaseAction } from '../types/redux-types'; +import { recordNotifPermissionAlertActionType } from '../utils/push-alerts.js'; + +function reduceAlertStore(state: AlertStore, action: BaseAction): AlertStore { + if (action.type === recordNotifPermissionAlertActionType) { + return { + ...state, + alertInfos: { + ...state.alertInfos, + [alertTypes.NOTIF_PERMISSION]: { + totalAlerts: + state.alertInfos[alertTypes.NOTIF_PERMISSION].totalAlerts + 1, + lastAlertTime: action.payload.time, + }, + }, + }; + } + return state; +} + +export { reduceAlertStore }; diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js --- a/lib/reducers/master-reducer.js +++ b/lib/reducers/master-reducer.js @@ -1,5 +1,6 @@ // @flow +import { reduceAlertStore } from './alert-reducer.js'; import { reduceAuxUserStore } from './aux-user-reducer.js'; import reduceCalendarFilters from './calendar-filters-reducer.js'; import { reduceCommunityStore } from './community-reducer.js'; @@ -16,7 +17,6 @@ import { reduceLoadingStatuses } from './loading-reducer.js'; import { reduceMessageStore } from './message-reducer.js'; import reduceBaseNavInfo from './nav-reducer.js'; -import { reduceNotifPermissionAlertInfo } from './notif-permission-alert-info-reducer.js'; import policiesReducer from './policies-reducer.js'; import reduceReportStore from './report-store-reducer.js'; import reduceServicesAccessToken from './services-access-token-reducer.js'; @@ -197,10 +197,7 @@ action, threadStore, ), - notifPermissionAlertInfo: reduceNotifPermissionAlertInfo( - state.notifPermissionAlertInfo, - action, - ), + alertStore: reduceAlertStore(state.alertStore, action), lifecycleState: reduceLifecycleState(state.lifecycleState, action), enabledApps: reduceEnabledApps(state.enabledApps, action), reportStore, diff --git a/lib/reducers/notif-permission-alert-info-reducer.js b/lib/reducers/notif-permission-alert-info-reducer.js deleted file mode 100644 --- a/lib/reducers/notif-permission-alert-info-reducer.js +++ /dev/null @@ -1,20 +0,0 @@ -// @flow - -import type { AlertInfo } from '../types/alert-types.js'; -import type { BaseAction } from '../types/redux-types'; -import { recordNotifPermissionAlertActionType } from '../utils/push-alerts.js'; - -function reduceNotifPermissionAlertInfo( - state: AlertInfo, - action: BaseAction, -): AlertInfo { - if (action.type === recordNotifPermissionAlertActionType) { - return { - totalAlerts: state.totalAlerts + 1, - lastAlertTime: action.payload.time, - }; - } - return state; -} - -export { reduceNotifPermissionAlertInfo }; 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 @@ -15,6 +15,7 @@ QueueActivityUpdatesPayload, SetThreadUnreadStatusPayload, } from './activity-types.js'; +import type { AlertStore } from './alert-types.js'; import type { AuxUserStore, SetFarcasterFriendsFIDPayload, @@ -138,7 +139,6 @@ SetLateResponsePayload, UpdateKeyserverReachabilityPayload, } from '../keyserver-conn/keyserver-conn-types.js'; -import type { AlertInfo } from '../types/alert-types.js'; export type BaseAppState = { +navInfo: NavInfo, @@ -150,7 +150,7 @@ +messageStore: MessageStore, +loadingStatuses: { [key: string]: { [idx: number]: LoadingStatus } }, +calendarFilters: $ReadOnlyArray, - +notifPermissionAlertInfo: AlertInfo, + +alertStore: AlertStore, +watchedThreadIDs: $ReadOnlyArray, +lifecycleState: LifecycleState, +enabledApps: EnabledApps, 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 @@ -2,7 +2,7 @@ import { authoritativeKeyserverID } from './authoritative-keyserver.js'; import { resetUserSpecificState } from './reducers-utils.js'; -import { defaultAlertInfo } from '../types/alert-types.js'; +import { defaultAlertInfo, alertTypes } from '../types/alert-types.js'; import { defaultWebEnabledApps } from '../types/enabled-apps.js'; import { defaultCalendarFilters } from '../types/filter-types.js'; import { defaultKeyserverInfo } from '../types/keyserver-types.js'; @@ -46,7 +46,11 @@ loadingStatuses: {}, calendarFilters: defaultCalendarFilters, dataLoaded: false, - notifPermissionAlertInfo: defaultAlertInfo, + alertStore: { + alertInfos: { + [alertTypes.NOTIF_PERMISSION]: defaultAlertInfo, + }, + }, watchedThreadIDs: [], lifecycleState: 'active', enabledApps: defaultWebEnabledApps, diff --git a/native/push/push-handler.react.js b/native/push/push-handler.react.js --- a/native/push/push-handler.react.js +++ b/native/push/push-handler.react.js @@ -28,7 +28,7 @@ } from 'lib/selectors/thread-selectors.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; import { mergePrefixIntoBody } from 'lib/shared/notif-utils.js'; -import type { AlertInfo } from 'lib/types/alert-types.js'; +import { alertTypes, type AlertInfo } from 'lib/types/alert-types.js'; import type { RawMessageInfo } from 'lib/types/message-types.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import type { Dispatch } from 'lib/types/redux-types.js'; @@ -779,7 +779,7 @@ const deviceTokens = useSelector(deviceTokensSelector); const threadInfos = useSelector(threadInfoSelector); const notifPermissionAlertInfo = useSelector( - state => state.notifPermissionAlertInfo, + state => state.alertStore.alertInfos[alertTypes.NOTIF_PERMISSION], ); const allUpdatesCurrentAsOf = useSelector(allUpdatesCurrentAsOfSelector); const activeTheme = useSelector(state => state.globalThemeInfo.activeTheme); 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 @@ -3,7 +3,7 @@ import { Platform } from 'react-native'; import Orientation from 'react-native-orientation-locker'; -import { defaultAlertInfo } from 'lib/types/alert-types.js'; +import { defaultAlertInfo, alertTypes } from 'lib/types/alert-types.js'; import { defaultEnabledApps } from 'lib/types/enabled-apps.js'; import { defaultCalendarFilters } from 'lib/types/filter-types.js'; import { defaultKeyserverInfo } from 'lib/types/keyserver-types.js'; @@ -43,7 +43,11 @@ calendarFilters: defaultCalendarFilters, dataLoaded: false, customServer: natNodeServer, - notifPermissionAlertInfo: defaultAlertInfo, + alertStore: { + alertInfos: { + [alertTypes.NOTIF_PERMISSION]: defaultAlertInfo, + }, + }, watchedThreadIDs: [], lifecycleState: 'active', enabledApps: defaultEnabledApps, diff --git a/native/redux/state-types.js b/native/redux/state-types.js --- a/native/redux/state-types.js +++ b/native/redux/state-types.js @@ -3,7 +3,7 @@ import type { Orientations } from 'react-native-orientation-locker'; import type { PersistState } from 'redux-persist/es/types.js'; -import type { AlertInfo } from 'lib/types/alert-types.js'; +import type { AlertStore } from 'lib/types/alert-types.js'; import type { AuxUserStore } from 'lib/types/aux-user-types.js'; import type { CommunityStore } from 'lib/types/community-types.js'; import type { DBOpsStore } from 'lib/types/db-ops-types'; @@ -58,7 +58,7 @@ +calendarFilters: $ReadOnlyArray, +dataLoaded: boolean, +customServer: ?string, - +notifPermissionAlertInfo: AlertInfo, + +alertStore: AlertStore, +watchedThreadIDs: $ReadOnlyArray, +lifecycleState: LifecycleState, +enabledApps: EnabledApps, diff --git a/web/push-notif/push-notifs-handler.js b/web/push-notif/push-notifs-handler.js --- a/web/push-notif/push-notifs-handler.js +++ b/web/push-notif/push-notifs-handler.js @@ -9,6 +9,7 @@ import { useModalContext } from 'lib/components/modal-provider.react.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; +import { alertTypes } from 'lib/types/alert-types.js'; import { isDesktopPlatform } from 'lib/types/device-types.js'; import { getConfig } from 'lib/utils/config.js'; import { convertNonPendingIDToNewSchema } from 'lib/utils/migration-utils.js'; @@ -156,7 +157,7 @@ const createPushSubscription = useCreatePushSubscription(); const notifPermissionAlertInfo = useSelector( - state => state.notifPermissionAlertInfo, + state => state.alertStore.alertInfos[alertTypes.NOTIF_PERMISSION], ); const modalContext = useModalContext(); 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 @@ -1,6 +1,6 @@ // @flow -import { defaultAlertInfo } from 'lib/types/alert-types.js'; +import { defaultAlertInfo, alertTypes } from 'lib/types/alert-types.js'; import { defaultWebEnabledApps } from 'lib/types/enabled-apps.js'; import { defaultCalendarFilters } from 'lib/types/filter-types.js'; import { defaultKeyserverInfo } from 'lib/types/keyserver-types.js'; @@ -44,7 +44,11 @@ loadingStatuses: {}, calendarFilters: defaultCalendarFilters, dataLoaded: false, - notifPermissionAlertInfo: defaultAlertInfo, + alertStore: { + alertInfos: { + [alertTypes.NOTIF_PERMISSION]: defaultAlertInfo, + }, + }, watchedThreadIDs: [], lifecycleState: 'active', enabledApps: defaultWebEnabledApps, diff --git a/web/redux/persist.js b/web/redux/persist.js --- a/web/redux/persist.js +++ b/web/redux/persist.js @@ -47,7 +47,7 @@ const persistWhitelist = [ 'enabledApps', - 'notifPermissionAlertInfo', + 'alertStore', 'commServicesAccessToken', 'keyserverStore', 'globalThemeInfo', diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js --- a/web/redux/redux-setup.js +++ b/web/redux/redux-setup.js @@ -30,7 +30,7 @@ identityInvalidSessionDowngrade, invalidSessionRecovery, } from 'lib/shared/session-utils.js'; -import type { AlertInfo } from 'lib/types/alert-types.js'; +import type { AlertStore } from 'lib/types/alert-types.js'; import type { AuxUserStore } from 'lib/types/aux-user-types.js'; import type { CommunityStore } from 'lib/types/community-types.js'; import type { MessageID, DBOpsStore } from 'lib/types/db-ops-types.js'; @@ -102,7 +102,7 @@ +calendarFilters: $ReadOnlyArray, +communityPickerStore: CommunityPickerStore, +windowDimensions: WindowDimensions, - +notifPermissionAlertInfo: AlertInfo, + +alertStore: AlertStore, +watchedThreadIDs: $ReadOnlyArray, +lifecycleState: LifecycleState, +enabledApps: EnabledApps,