diff --git a/lib/types/alert-types.js b/lib/types/alert-types.js index e62e692bf..0f131511f 100644 --- a/lib/types/alert-types.js +++ b/lib/types/alert-types.js @@ -1,27 +1,33 @@ // @flow const alertTypes = Object.freeze({ NOTIF_PERMISSION: 'notif-permission', + CONNECT_FARCASTER: 'connect-farcaster', }); type AlertType = $Values; export type AlertInfo = { +totalAlerts: number, +lastAlertTime: number, }; export type AlertInfos = { +[alertID: AlertType]: AlertInfo, }; export type AlertStore = { +alertInfos: AlertInfos, }; const defaultAlertInfo: AlertInfo = { totalAlerts: 0, lastAlertTime: 0, }; -export { alertTypes, defaultAlertInfo }; +const defaultAlertInfos: AlertInfos = Object.freeze({ + [alertTypes.NOTIF_PERMISSION]: defaultAlertInfo, + [alertTypes.CONNECT_FARCASTER]: defaultAlertInfo, +}); + +export { alertTypes, defaultAlertInfo, defaultAlertInfos }; diff --git a/lib/utils/reducers-utils.test.js b/lib/utils/reducers-utils.test.js index 6eb85eef9..b40f97c4b 100644 --- a/lib/utils/reducers-utils.test.js +++ b/lib/utils/reducers-utils.test.js @@ -1,133 +1,131 @@ // @flow import { authoritativeKeyserverID } from './authoritative-keyserver.js'; import { resetUserSpecificState } from './reducers-utils.js'; -import { defaultAlertInfo, alertTypes } from '../types/alert-types.js'; +import { defaultAlertInfos } 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'; import { defaultGlobalThemeInfo } from '../types/theme-types.js'; jest.mock('./config.js'); describe('resetUserSpecificState', () => { let defaultState; let state; beforeAll(() => { defaultState = { navInfo: { activeChatThreadID: null, startDate: '', endDate: '', tab: 'chat', }, currentUserInfo: null, draftStore: { drafts: {} }, entryStore: { entryInfos: {}, daysToEntries: {}, lastUserInteractionCalendar: 0, }, threadStore: { threadInfos: {}, }, userStore: { userInfos: {}, }, messageStore: { messages: {}, threads: {}, local: {}, currentAsOf: { [authoritativeKeyserverID()]: 0 }, }, windowActive: true, pushApiPublicKey: null, loadingStatuses: {}, calendarFilters: defaultCalendarFilters, dataLoaded: false, alertStore: { - alertInfos: { - [alertTypes.NOTIF_PERMISSION]: defaultAlertInfo, - }, + alertInfos: defaultAlertInfos, }, watchedThreadIDs: [], lifecycleState: 'active', enabledApps: defaultWebEnabledApps, reportStore: { enabledReports: { crashReports: false, inconsistencyReports: false, mediaReports: false, }, queuedReports: [], }, _persist: null, userPolicies: {}, commServicesAccessToken: null, inviteLinksStore: { links: {}, }, actualizedCalendarQuery: { startDate: '', endDate: '', filters: defaultCalendarFilters, }, communityPickerStore: { chat: null, calendar: null }, keyserverStore: { keyserverInfos: { [authoritativeKeyserverID()]: defaultKeyserverInfo('url'), }, }, threadActivityStore: {}, initialStateLoaded: false, integrityStore: { threadHashes: {}, threadHashingStatus: 'starting' }, globalThemeInfo: defaultGlobalThemeInfo, customServer: null, communityStore: { communityInfos: {}, }, dbOpsStore: { queuedOps: [], }, syncedMetadataStore: { syncedMetadata: {}, }, auxUserStore: { auxUserInfos: {}, }, }; state = { ...defaultState, globalThemeInfo: { activeTheme: 'light', preference: 'light', systemTheme: null, }, communityPickerStore: { chat: '256|1', calendar: '256|1' }, navInfo: { activeChatThreadID: null, startDate: '2023-02-02', endDate: '2023-03-02', tab: 'calendar', }, }; }); it("doesn't reset fields named in nonUserSpecificFields", () => { const nonUserSpecificFields = [ 'globalThemeInfo', 'communityPickerStore', 'navInfo', ]; expect( resetUserSpecificState(state, defaultState, nonUserSpecificFields), ).toEqual(state); }); it('resets fields not named in nonUserSpecificFields', () => { expect(resetUserSpecificState(state, defaultState, [])).toEqual( defaultState, ); }); }); diff --git a/native/redux/default-state.js b/native/redux/default-state.js index bd2514a8f..1b27af5c2 100644 --- a/native/redux/default-state.js +++ b/native/redux/default-state.js @@ -1,101 +1,99 @@ // @flow import { Platform } from 'react-native'; import Orientation from 'react-native-orientation-locker'; -import { defaultAlertInfo, alertTypes } from 'lib/types/alert-types.js'; +import { defaultAlertInfos } 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'; import { defaultGlobalThemeInfo } from 'lib/types/theme-types.js'; import { defaultDimensionsInfo } from './dimensions-updater.react.js'; import type { AppState } from './state-types.js'; import { authoritativeKeyserverID } from '../authoritative-keyserver.js'; import { defaultNavInfo } from '../navigation/default-state.js'; import { defaultDeviceCameraInfo } from '../types/camera.js'; import { defaultConnectivityInfo } from '../types/connectivity.js'; import { defaultURLPrefix, natNodeServer } from '../utils/url-utils.js'; const defaultState = ({ navInfo: defaultNavInfo, currentUserInfo: null, draftStore: { drafts: {} }, entryStore: { entryInfos: {}, daysToEntries: {}, lastUserInteractionCalendar: 0, }, threadStore: { threadInfos: {}, }, userStore: { userInfos: {}, }, messageStore: { messages: {}, threads: {}, local: {}, currentAsOf: { [authoritativeKeyserverID]: 0 }, }, storeLoaded: false, loadingStatuses: {}, calendarFilters: defaultCalendarFilters, dataLoaded: false, customServer: natNodeServer, alertStore: { - alertInfos: { - [alertTypes.NOTIF_PERMISSION]: defaultAlertInfo, - }, + alertInfos: defaultAlertInfos, }, watchedThreadIDs: [], lifecycleState: 'active', enabledApps: defaultEnabledApps, reportStore: { enabledReports: { crashReports: __DEV__, inconsistencyReports: __DEV__, mediaReports: __DEV__, }, queuedReports: [], }, _persist: null, dimensions: defaultDimensionsInfo, connectivity: defaultConnectivityInfo, globalThemeInfo: defaultGlobalThemeInfo, deviceCameraInfo: defaultDeviceCameraInfo, deviceOrientation: Orientation.getInitialOrientation(), frozen: false, userPolicies: {}, commServicesAccessToken: null, inviteLinksStore: { links: {}, }, keyserverStore: { keyserverInfos: { [authoritativeKeyserverID]: defaultKeyserverInfo( defaultURLPrefix, Platform.OS, ), }, }, localSettings: { isBackupEnabled: false, }, threadActivityStore: {}, integrityStore: { threadHashes: {}, threadHashingStatus: 'starting' }, communityStore: { communityInfos: {}, }, auxUserStore: { auxUserInfos: {}, }, dbOpsStore: { queuedOps: [], }, syncedMetadataStore: { syncedMetadata: {}, }, }: AppState); export { defaultState }; diff --git a/web/redux/default-state.js b/web/redux/default-state.js index 33eff5af3..b9b2622c6 100644 --- a/web/redux/default-state.js +++ b/web/redux/default-state.js @@ -1,97 +1,95 @@ // @flow -import { defaultAlertInfo, alertTypes } from 'lib/types/alert-types.js'; +import { defaultAlertInfos } 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'; import { defaultGlobalThemeInfo } from 'lib/types/theme-types.js'; import type { AppState } from './redux-setup.js'; import { authoritativeKeyserverID } from '../authoritative-keyserver.js'; import electron from '../electron.js'; declare var keyserverURL: string; const defaultWebState: AppState = Object.freeze({ navInfo: { activeChatThreadID: null, startDate: '', endDate: '', tab: 'chat', }, currentUserInfo: null, draftStore: { drafts: {} }, entryStore: { entryInfos: {}, daysToEntries: {}, lastUserInteractionCalendar: 0, }, threadStore: { threadInfos: {}, }, userStore: { userInfos: {}, }, messageStore: { messages: {}, threads: {}, local: {}, currentAsOf: { [authoritativeKeyserverID]: 0 }, }, windowActive: true, pushApiPublicKey: null, windowDimensions: { width: window.width, height: window.height }, loadingStatuses: {}, calendarFilters: defaultCalendarFilters, dataLoaded: false, alertStore: { - alertInfos: { - [alertTypes.NOTIF_PERMISSION]: defaultAlertInfo, - }, + alertInfos: defaultAlertInfos, }, watchedThreadIDs: [], lifecycleState: 'active', enabledApps: defaultWebEnabledApps, reportStore: { enabledReports: { crashReports: false, inconsistencyReports: false, mediaReports: false, }, queuedReports: [], }, _persist: null, userPolicies: {}, commServicesAccessToken: null, inviteLinksStore: { links: {}, }, communityPickerStore: { chat: null, calendar: null }, keyserverStore: { keyserverInfos: { [authoritativeKeyserverID]: defaultKeyserverInfo( keyserverURL, electron?.platform ?? 'web', ), }, }, threadActivityStore: {}, initialStateLoaded: false, integrityStore: { threadHashes: {}, threadHashingStatus: 'starting' }, globalThemeInfo: defaultGlobalThemeInfo, customServer: null, communityStore: { communityInfos: {}, }, dbOpsStore: { queuedOps: [], }, syncedMetadataStore: { syncedMetadata: {}, }, auxUserStore: { auxUserInfos: {}, }, }); export { defaultWebState };