diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js --- a/native/redux/redux-setup.js +++ b/native/redux/redux-setup.js @@ -13,6 +13,7 @@ logInActionTypes, keyserverAuthActionTypes, deleteKeyserverAccountActionTypes, + identityRegisterActionTypes, } from 'lib/actions/user-actions.js'; import { setNewSessionActionType } from 'lib/keyserver-conn/keyserver-conn-types.js'; import type { ThreadStoreOperation } from 'lib/ops/thread-store-ops.js'; @@ -28,6 +29,7 @@ import { rehydrateActionType } from 'lib/types/redux-types.js'; import type { SetSessionPayload } from 'lib/types/session-types.js'; import { reduxLoggerMiddleware } from 'lib/utils/action-logger.js'; +import { resetUserSpecificStateOnIdentityActions } from 'lib/utils/reducers-utils.js'; import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import { @@ -46,6 +48,7 @@ import { persistConfig, setPersistor } from './persist.js'; import { onStateDifference } from './redux-debug-utils.js'; import { processDBStoreOperations } from './redux-utils.js'; +import { nonUserSpecificFieldsNative } from './state-types.js'; import type { AppState } from './state-types.js'; import { getGlobalNavContext } from '../navigation/icky-global.js'; import { activeMessageListSelector } from '../navigation/nav-selectors.js'; @@ -116,21 +119,7 @@ action.payload.preRequestUserState, action.payload.keyserverID, )) || - (action.type === logOutActionTypes.success && - invalidSessionDowngrade( - state, - action.payload.currentUserInfo, - action.payload.preRequestUserState, - ashoatKeyserverID, - )) || (action.type === deleteKeyserverAccountActionTypes.success && - invalidSessionDowngrade( - state, - action.payload.currentUserInfo, - action.payload.preRequestUserState, - ashoatKeyserverID, - )) || - (action.type === deleteAccountActionTypes.success && invalidSessionDowngrade( state, action.payload.currentUserInfo, @@ -142,6 +131,35 @@ ...state, loadingStatuses: reduceLoadingStatuses(state.loadingStatuses, action), }; + } else if ( + action.type === logOutActionTypes.success || + action.type === deleteAccountActionTypes.success + ) { + if ( + invalidSessionDowngrade( + state, + action.payload.currentUserInfo, + action.payload.preRequestUserState, + ashoatKeyserverID, + ) + ) { + return { + ...state, + loadingStatuses: reduceLoadingStatuses(state.loadingStatuses, action), + }; + } + + state = resetUserSpecificStateOnIdentityActions( + state, + defaultState, + nonUserSpecificFieldsNative, + ); + } else if (action.type === identityRegisterActionTypes.success) { + state = resetUserSpecificStateOnIdentityActions( + state, + defaultState, + nonUserSpecificFieldsNative, + ); } if ( (action.type === setNewSessionActionType && 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 @@ -4,20 +4,24 @@ 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 { thisMonthDates } from 'lib/utils/date-utils.js'; import { defaultNotifPermissionAlertInfo } from 'lib/utils/push-alerts.js'; import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import type { AppState } from './redux-setup.js'; +import type { NavInfo } from '../types/nav-types.js'; declare var keyserverURL: string; +const defaultNavInfo: NavInfo = { + activeChatThreadID: null, + startDate: thisMonthDates().startDate, + endDate: thisMonthDates().endDate, + tab: 'chat', +}; + const defaultWebState: AppState = Object.freeze({ - navInfo: { - activeChatThreadID: null, - startDate: '', - endDate: '', - tab: 'chat', - }, + navInfo: defaultNavInfo, currentUserInfo: null, draftStore: { drafts: {} }, entryStore: { 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 @@ -7,6 +7,7 @@ logOutActionTypes, deleteKeyserverAccountActionTypes, deleteAccountActionTypes, + identityRegisterActionTypes, } from 'lib/actions/user-actions.js'; import { setNewSessionActionType } from 'lib/keyserver-conn/keyserver-conn-types.js'; import { @@ -38,6 +39,7 @@ import type { ThreadStore } from 'lib/types/thread-types.js'; import type { CurrentUserInfo, UserStore } from 'lib/types/user-types.js'; import type { NotifPermissionAlertInfo } from 'lib/utils/push-alerts.js'; +import { resetUserSpecificStateOnIdentityActions } from 'lib/utils/reducers-utils.js'; import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import { @@ -48,6 +50,7 @@ } from './action-types.js'; import { reduceCommunityPickerStore } from './community-picker-reducer.js'; import { reduceCryptoStore, setCryptoStore } from './crypto-store-reducer.js'; +import { defaultWebState } from './default-state.js'; import reduceNavInfo from './nav-reducer.js'; import { onStateDifference } from './redux-debug-utils.js'; import { getVisibility } from './visibility.js'; @@ -217,32 +220,47 @@ }, }; } else if ( - (action.type === logOutActionTypes.success && - invalidSessionDowngrade( - oldState, - action.payload.currentUserInfo, - action.payload.preRequestUserState, - ashoatKeyserverID, - )) || - (action.type === deleteKeyserverAccountActionTypes.success && - invalidSessionDowngrade( - oldState, - action.payload.currentUserInfo, - action.payload.preRequestUserState, - ashoatKeyserverID, - )) || - (action.type === deleteAccountActionTypes.success && - invalidSessionDowngrade( - state, - action.payload.currentUserInfo, - action.payload.preRequestUserState, - ashoatKeyserverID, - )) + action.type === deleteKeyserverAccountActionTypes.success && + invalidSessionDowngrade( + oldState, + action.payload.currentUserInfo, + action.payload.preRequestUserState, + ashoatKeyserverID, + ) ) { return { ...oldState, loadingStatuses: reduceLoadingStatuses(state.loadingStatuses, action), }; + } else if ( + action.type === logOutActionTypes.success || + action.type === deleteAccountActionTypes.success + ) { + if ( + invalidSessionDowngrade( + oldState, + action.payload.currentUserInfo, + action.payload.preRequestUserState, + ashoatKeyserverID, + ) + ) { + return { + ...oldState, + loadingStatuses: reduceLoadingStatuses(state.loadingStatuses, action), + }; + } + + state = resetUserSpecificStateOnIdentityActions( + state, + defaultWebState, + nonUserSpecificFieldsWeb, + ); + } else if (action.type === identityRegisterActionTypes.success) { + state = resetUserSpecificStateOnIdentityActions( + state, + defaultWebState, + nonUserSpecificFieldsWeb, + ); } if (