diff --git a/keyserver/src/responders/website-responders.js b/keyserver/src/responders/website-responders.js --- a/keyserver/src/responders/website-responders.js +++ b/keyserver/src/responders/website-responders.js @@ -208,17 +208,14 @@ 'default queuedActivityUpdates', _isEqual([]), ), - actualizedCalendarQuery: tShape({ - startDate: t.String, - endDate: t.String, - filters: t.irreducible( - 'default filters', - _isEqual(defaultCalendarFilters), - ), - }), lateResponses: t.irreducible('default lateResponses', _isEqual([])), showDisconnectedBar: tBool(false), }), + actualizedCalendarQuery: tShape({ + startDate: t.String, + endDate: t.String, + filters: t.irreducible('default filters', _isEqual(defaultCalendarFilters)), + }), watchedThreadIDs: t.irreducible('default watchedThreadIDs', _isEqual([])), lifecycleState: tString('active'), enabledApps: t.irreducible( @@ -595,10 +592,8 @@ communityPickerStore: { chat: null, calendar: null }, windowDimensions: { width: 0, height: 0 }, notifPermissionAlertInfo: defaultNotifPermissionAlertInfo, - connection: (async () => ({ - ...defaultConnectionInfo(viewer.platform ?? 'web', viewer.timeZone), - actualizedCalendarQuery: await calendarQueryPromise, - }))(), + connection: defaultConnectionInfo, + actualizedCalendarQuery: calendarQueryPromise, watchedThreadIDs: [], lifecycleState: 'active', enabledApps: defaultWebEnabledApps, diff --git a/lib/reducers/calendar-query-reducer.js b/lib/reducers/calendar-query-reducer.js new file mode 100644 --- /dev/null +++ b/lib/reducers/calendar-query-reducer.js @@ -0,0 +1,49 @@ +// @flow + +import { updateCalendarQueryActionTypes } from '../actions/entry-actions.js'; +import { siweAuthActionTypes } from '../actions/siwe-actions.js'; +import { + logOutActionTypes, + deleteAccountActionTypes, + logInActionTypes, + registerActionTypes, +} from '../actions/user-actions.js'; +import { defaultCalendarQuery } from '../types/entry-types.js'; +import type { CalendarQuery } from '../types/entry-types.js'; +import { type BaseAction } from '../types/redux-types.js'; +import { + fullStateSyncActionType, + incrementalStateSyncActionType, +} from '../types/socket-types.js'; +import { setNewSessionActionType } from '../utils/action-utils.js'; +import { getConfig } from '../utils/config.js'; + +function reduceCalendarQuery( + state: CalendarQuery, + action: BaseAction, +): CalendarQuery { + if ( + action.type === logOutActionTypes.success || + action.type === deleteAccountActionTypes.success || + (action.type === setNewSessionActionType && + action.payload.sessionChange.cookieInvalidated) + ) { + return defaultCalendarQuery(getConfig().platformDetails.platform); + } else if ( + action.type === logInActionTypes.success || + action.type === siweAuthActionTypes.success + ) { + return action.payload.calendarResult.calendarQuery; + } else if ( + action.type === registerActionTypes.success || + action.type === updateCalendarQueryActionTypes.success || + action.type === fullStateSyncActionType || + action.type === incrementalStateSyncActionType + ) { + return action.payload.calendarQuery; + } + + return state; +} + +export { reduceCalendarQuery }; diff --git a/lib/reducers/connection-reducer.js b/lib/reducers/connection-reducer.js --- a/lib/reducers/connection-reducer.js +++ b/lib/reducers/connection-reducer.js @@ -2,27 +2,19 @@ import { unsupervisedBackgroundActionType } from './lifecycle-state-reducer.js'; import { updateActivityActionTypes } from '../actions/activity-actions.js'; -import { updateCalendarQueryActionTypes } from '../actions/entry-actions.js'; -import { siweAuthActionTypes } from '../actions/siwe-actions.js'; import { logOutActionTypes, deleteAccountActionTypes, - logInActionTypes, - registerActionTypes, } from '../actions/user-actions.js'; import { queueActivityUpdatesActionType } from '../types/activity-types.js'; -import { defaultCalendarQuery } from '../types/entry-types.js'; import { type BaseAction, rehydrateActionType } from '../types/redux-types.js'; import { type ConnectionInfo, updateConnectionStatusActionType, - fullStateSyncActionType, - incrementalStateSyncActionType, setLateResponseActionType, updateDisconnectedBarActionType, } from '../types/socket-types.js'; import { setNewSessionActionType } from '../utils/action-utils.js'; -import { getConfig } from '../utils/config.js'; export default function reduceConnectionInfo( state: ConnectionInfo, @@ -70,27 +62,6 @@ return { ...state, queuedActivityUpdates: [], - actualizedCalendarQuery: defaultCalendarQuery( - getConfig().platformDetails.platform, - ), - }; - } else if ( - action.type === logInActionTypes.success || - action.type === siweAuthActionTypes.success - ) { - return { - ...state, - actualizedCalendarQuery: action.payload.calendarResult.calendarQuery, - }; - } else if ( - action.type === registerActionTypes.success || - action.type === updateCalendarQueryActionTypes.success || - action.type === fullStateSyncActionType || - action.type === incrementalStateSyncActionType - ) { - return { - ...state, - actualizedCalendarQuery: action.payload.calendarQuery, }; } else if (action.type === rehydrateActionType) { if (!action.payload || !action.payload.connection) { 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,6 +1,7 @@ // @flow import reduceCalendarFilters from './calendar-filters-reducer.js'; +import { reduceCalendarQuery } from './calendar-query-reducer.js'; import reduceConnectionInfo from './connection-reducer.js'; import reduceDataLoaded from './data-loaded-reducer.js'; import { reduceDeviceToken } from './device-token-reducer.js'; @@ -131,6 +132,10 @@ action, ), connection, + actualizedCalendarQuery: reduceCalendarQuery( + state.actualizedCalendarQuery, + action, + ), lifecycleState: reduceLifecycleState(state.lifecycleState, action), enabledApps: reduceEnabledApps(state.enabledApps, action), reportStore, diff --git a/lib/socket/calendar-query-handler.react.js b/lib/socket/calendar-query-handler.react.js --- a/lib/socket/calendar-query-handler.react.js +++ b/lib/socket/calendar-query-handler.react.js @@ -29,6 +29,7 @@ type Props = { ...BaseProps, +connection: ConnectionInfo, + +calendarQuery: CalendarQuery, +lastUserInteractionCalendar: number, +foreground: boolean, +dispatchActionPromise: DispatchActionPromise, @@ -43,7 +44,7 @@ constructor(props: Props) { super(props); - this.serverCalendarQuery = this.props.connection.actualizedCalendarQuery; + this.serverCalendarQuery = this.props.calendarQuery; } componentDidMount() { @@ -53,19 +54,19 @@ } componentDidUpdate(prevProps: Props) { - const { actualizedCalendarQuery } = this.props.connection; + const { calendarQuery } = this.props; if (this.props.connection.status !== 'connected') { - if (!_isEqual(this.serverCalendarQuery)(actualizedCalendarQuery)) { - this.serverCalendarQuery = actualizedCalendarQuery; + if (!_isEqual(this.serverCalendarQuery)(calendarQuery)) { + this.serverCalendarQuery = calendarQuery; } return; } if ( - !_isEqual(this.serverCalendarQuery)(actualizedCalendarQuery) && - _isEqual(this.props.currentCalendarQuery())(actualizedCalendarQuery) + !_isEqual(this.serverCalendarQuery)(calendarQuery) && + _isEqual(this.props.currentCalendarQuery())(calendarQuery) ) { - this.serverCalendarQuery = actualizedCalendarQuery; + this.serverCalendarQuery = calendarQuery; } const shouldUpdate = @@ -130,11 +131,13 @@ const foreground = useIsAppForegrounded(); const callUpdateCalendarQuery = useServerCall(updateCalendarQuery); const dispatchActionPromise = useDispatchActionPromise(); + const calendarQuery = useSelector(state => state.actualizedCalendarQuery); return ( , +notifPermissionAlertInfo: NotifPermissionAlertInfo, +connection: ConnectionInfo, + +actualizedCalendarQuery: CalendarQuery, +watchedThreadIDs: $ReadOnlyArray, +lifecycleState: LifecycleState, +enabledApps: EnabledApps, diff --git a/lib/types/socket-types.js b/lib/types/socket-types.js --- a/lib/types/socket-types.js +++ b/lib/types/socket-types.js @@ -9,14 +9,11 @@ type UpdateActivityResult, updateActivityResultValidator, } from './activity-types.js'; -import type { Platform } from './device-types.js'; import type { APIRequest } from './endpoints.js'; import { type RawEntryInfo, rawEntryInfoValidator, type CalendarQuery, - calendarQueryValidator, - defaultCalendarQuery, } from './entry-types.js'; import { type MessagesResponse, @@ -471,7 +468,6 @@ export type ConnectionInfo = { +status: ConnectionStatus, +queuedActivityUpdates: $ReadOnlyArray, - +actualizedCalendarQuery: CalendarQuery, +lateResponses: $ReadOnlyArray, +showDisconnectedBar: boolean, }; @@ -486,21 +482,15 @@ 'disconnected', ]), queuedActivityUpdates: t.list(activityUpdateValidator), - actualizedCalendarQuery: calendarQueryValidator, lateResponses: t.list(t.Number), showDisconnectedBar: t.Boolean, }); -export const defaultConnectionInfo = ( - platform: Platform, - timeZone?: ?string, -): ConnectionInfo => - ({ - status: 'connecting', - queuedActivityUpdates: [], - actualizedCalendarQuery: defaultCalendarQuery(platform, timeZone), - lateResponses: [], - showDisconnectedBar: false, - }: ConnectionInfo); +export const defaultConnectionInfo: ConnectionInfo = { + status: 'connecting', + queuedActivityUpdates: [], + lateResponses: [], + showDisconnectedBar: false, +}; export const updateConnectionStatusActionType = 'UPDATE_CONNECTION_STATUS'; export type UpdateConnectionStatusPayload = { +status: ConnectionStatus, diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -39,6 +39,7 @@ unshimFunc, } from 'lib/shared/unshim-utils.js'; import { defaultEnabledApps } from 'lib/types/enabled-apps.js'; +import { defaultCalendarQuery } from 'lib/types/entry-types.js'; import { defaultCalendarFilters } from 'lib/types/filter-types.js'; import { messageTypes } from 'lib/types/message-types-enum.js'; import { @@ -141,7 +142,10 @@ ...state, pingTimestamps: undefined, activeServerRequests: undefined, - connection: defaultConnectionInfo(Platform.OS), + connection: { + ...defaultConnectionInfo, + actualizedCalendarQuery: defaultCalendarQuery(Platform.OS), + }, watchedThreadIDs: [], entryStore: { ...state.entryStore, @@ -736,6 +740,16 @@ connection, }; }, + [50]: async state => { + const { connection, ...rest } = state; + const { actualizedCalendarQuery, ...connectionRest } = connection; + + return { + ...rest, + connection: connectionRest, + actualizedCalendarQuery, + }; + }, }; // After migration 31, we'll no longer want to persist `messageStore.messages` @@ -830,7 +844,7 @@ 'storeLoaded', ], debug: __DEV__, - version: 49, + version: 50, transforms: [messageStoreMessagesBlocklistTransform, reportStoreTransform], migrate: (createAsyncMigrate(migrations, { debug: __DEV__ }): any), timeout: ((__DEV__ ? 0 : undefined): number | void), 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 @@ -22,6 +22,7 @@ } from 'lib/shared/session-utils.js'; import { isStaff } from 'lib/shared/staff-utils.js'; import { defaultEnabledApps } from 'lib/types/enabled-apps.js'; +import { defaultCalendarQuery } from 'lib/types/entry-types.js'; import { defaultCalendarFilters } from 'lib/types/filter-types.js'; import type { Dispatch, BaseAction } from 'lib/types/redux-types.js'; import { rehydrateActionType } from 'lib/types/redux-types.js'; @@ -94,7 +95,8 @@ dataLoaded: false, customServer: natNodeServer, notifPermissionAlertInfo: defaultNotifPermissionAlertInfo, - connection: defaultConnectionInfo(Platform.OS), + connection: defaultConnectionInfo, + actualizedCalendarQuery: defaultCalendarQuery(Platform.OS), 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 @@ -6,7 +6,7 @@ import type { LastCommunicatedPlatformDetails } from 'lib/types/device-types.js'; import type { DraftStore } from 'lib/types/draft-types.js'; import type { EnabledApps } from 'lib/types/enabled-apps.js'; -import type { EntryStore } from 'lib/types/entry-types.js'; +import type { EntryStore, CalendarQuery } from 'lib/types/entry-types.js'; import type { CalendarFilter } from 'lib/types/filter-types.js'; import type { KeyserverStore } from 'lib/types/keyserver-types.js'; import type { LifecycleState } from 'lib/types/lifecycle-state-types.js'; @@ -42,6 +42,7 @@ +customServer: ?string, +notifPermissionAlertInfo: NotifPermissionAlertInfo, +connection: ConnectionInfo, + +actualizedCalendarQuery: CalendarQuery, +watchedThreadIDs: $ReadOnlyArray, +lifecycleState: LifecycleState, +enabledApps: EnabledApps, 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 @@ -21,7 +21,7 @@ import type { LastCommunicatedPlatformDetails } from 'lib/types/device-types.js'; import type { DraftStore } from 'lib/types/draft-types.js'; import type { EnabledApps } from 'lib/types/enabled-apps.js'; -import type { EntryStore } from 'lib/types/entry-types.js'; +import type { EntryStore, CalendarQuery } from 'lib/types/entry-types.js'; import { type CalendarFilter } from 'lib/types/filter-types.js'; import type { KeyserverStore } from 'lib/types/keyserver-types.js'; import type { LifecycleState } from 'lib/types/lifecycle-state-types.js'; @@ -83,6 +83,7 @@ +deviceToken: ?string, +notifPermissionAlertInfo: NotifPermissionAlertInfo, +connection: ConnectionInfo, + +actualizedCalendarQuery: CalendarQuery, +watchedThreadIDs: $ReadOnlyArray, +lifecycleState: LifecycleState, +enabledApps: EnabledApps,