Page MenuHomePhabricator

D11144.id37438.diff
No OneTemporary

D11144.id37438.diff

diff --git a/lib/reducers/calendar-query-reducer.js b/lib/reducers/calendar-query-reducer.js
deleted file mode 100644
--- a/lib/reducers/calendar-query-reducer.js
+++ /dev/null
@@ -1,67 +0,0 @@
-// @flow
-
-import { removeKeyserverThreadIDsFromFilterList } from './calendar-filters-reducer.js';
-import { updateCalendarQueryActionTypes } from '../actions/entry-actions.js';
-import { siweAuthActionTypes } from '../actions/siwe-actions.js';
-import {
- logOutActionTypes,
- deleteKeyserverAccountActionTypes,
- logInActionTypes,
- keyserverRegisterActionTypes,
- deleteAccountActionTypes,
-} from '../actions/user-actions.js';
-import { setNewSessionActionType } from '../keyserver-conn/keyserver-conn-types.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 { getConfig } from '../utils/config.js';
-
-function reduceCalendarQuery(
- state: CalendarQuery,
- action: BaseAction,
-): CalendarQuery {
- if (
- action.type === logOutActionTypes.success ||
- action.type === deleteAccountActionTypes.success
- ) {
- return defaultCalendarQuery(getConfig().platformDetails.platform);
- } else if (
- action.type === setNewSessionActionType &&
- action.payload.sessionChange.cookieInvalidated
- ) {
- return {
- ...state,
- filters: removeKeyserverThreadIDsFromFilterList(state.filters, [
- action.payload.keyserverID,
- ]),
- };
- } else if (action.type === deleteKeyserverAccountActionTypes.success) {
- return {
- ...state,
- filters: removeKeyserverThreadIDsFromFilterList(
- state.filters,
- action.payload.keyserverIDs,
- ),
- };
- } else if (
- action.type === logInActionTypes.success ||
- action.type === siweAuthActionTypes.success
- ) {
- return action.payload.calendarResult.calendarQuery;
- } else if (
- action.type === keyserverRegisterActionTypes.success ||
- action.type === updateCalendarQueryActionTypes.success ||
- action.type === fullStateSyncActionType ||
- action.type === incrementalStateSyncActionType
- ) {
- return action.payload.calendarQuery;
- }
-
- return state;
-}
-
-export { reduceCalendarQuery };
diff --git a/lib/reducers/keyserver-reducer.js b/lib/reducers/keyserver-reducer.js
--- a/lib/reducers/keyserver-reducer.js
+++ b/lib/reducers/keyserver-reducer.js
@@ -1,5 +1,6 @@
// @flow
+import { filterThreadIDsInFilterList } from './calendar-filters-reducer.js';
import { unsupervisedBackgroundActionType } from './lifecycle-state-reducer.js';
import { updateActivityActionTypes } from '../actions/activity-actions.js';
import { setClientDBStoreActionType } from '../actions/client-db-store-actions.js';
@@ -7,6 +8,7 @@
updateLastCommunicatedPlatformDetailsActionType,
setDeviceTokenActionTypes,
} from '../actions/device-actions.js';
+import { updateCalendarQueryActionTypes } from '../actions/entry-actions.js';
import {
addKeyserverActionType,
removeKeyserverActionType,
@@ -21,6 +23,7 @@
logInActionTypes,
resetUserStateActionType,
} from '../actions/user-actions.js';
+import { extractKeyserverIDFromID } from '../keyserver-conn/keyserver-call-utils.js';
import {
setNewSessionActionType,
updateConnectionStatusActionType,
@@ -35,7 +38,9 @@
type RemoveKeyserversOperation,
type KeyserverStoreOperation,
} from '../ops/keyserver-store-ops.js';
+import { nonThreadCalendarFilters } from '../selectors/calendar-filter-selectors.js';
import { queueActivityUpdatesActionType } from '../types/activity-types.js';
+import { defaultCalendarQuery } from '../types/entry-types.js';
import type {
KeyserverInfos,
KeyserverStore,
@@ -170,6 +175,12 @@
if (sessionChange.cookieInvalidated) {
newKeyserverInfo = {
...newKeyserverInfo,
+ actualizedCalendarQuery: {
+ ...newKeyserverInfo.actualizedCalendarQuery,
+ filters: nonThreadCalendarFilters(
+ newKeyserverInfo.actualizedCalendarQuery.filters,
+ ),
+ },
connection: {
...newKeyserverInfo.connection,
queuedActivityUpdates: [],
@@ -215,6 +226,11 @@
const operations: ReplaceKeyserverOperation[] = [];
for (const keyserverID in updatesCurrentAsOf) {
+ const calendarFilters = filterThreadIDsInFilterList(
+ action.payload.calendarResult.calendarQuery.filters,
+ (threadID: string) =>
+ extractKeyserverIDFromID(threadID) === keyserverID,
+ );
operations.push({
type: 'replace_keyserver',
payload: {
@@ -223,6 +239,10 @@
...state.keyserverInfos[keyserverID],
updatesCurrentAsOf: updatesCurrentAsOf[keyserverID],
lastCommunicatedPlatformDetails: getConfig().platformDetails,
+ actualizedCalendarQuery: {
+ ...action.payload.calendarResult.calendarQuery,
+ filters: calendarFilters,
+ },
connection: {
...state.keyserverInfos[keyserverID].connection,
connectionIssue: null,
@@ -243,6 +263,7 @@
id: keyserverID,
keyserverInfo: {
...state.keyserverInfos[keyserverID],
+ actualizedCalendarQuery: action.payload.calendarQuery,
updatesCurrentAsOf: action.payload.updatesCurrentAsOf,
},
},
@@ -270,6 +291,7 @@
id: keyserverID,
keyserverInfo: {
...state.keyserverInfos[keyserverID],
+ actualizedCalendarQuery: action.payload.calendarQuery,
updatesCurrentAsOf: action.payload.updatesResult.currentAsOf,
deviceToken,
},
@@ -338,6 +360,7 @@
id: ashoatKeyserverID,
keyserverInfo: {
...state.keyserverInfos[ashoatKeyserverID],
+ actualizedCalendarQuery: action.payload.calendarQuery,
lastCommunicatedPlatformDetails: getConfig().platformDetails,
},
},
@@ -465,6 +488,9 @@
id: ashoatKeyserverID,
keyserverInfo: {
...state.keyserverInfos[ashoatKeyserverID],
+ actualizedCalendarQuery: defaultCalendarQuery(
+ getConfig().platformDetails.platform,
+ ),
connection: {
...oldConnection,
connectionIssue: null,
@@ -495,6 +521,9 @@
id: ashoatKeyserverID,
keyserverInfo: {
...state.keyserverInfos[ashoatKeyserverID],
+ actualizedCalendarQuery: defaultCalendarQuery(
+ getConfig().platformDetails.platform,
+ ),
connection: {
...oldConnection,
connectionIssue: null,
@@ -628,6 +657,31 @@
keyserverStore: state,
keyserverStoreOperations: [],
};
+ } else if (action.type === updateCalendarQueryActionTypes.success) {
+ const operations: ReplaceKeyserverOperation[] = [];
+ for (const keyserverID of action.payload.keyserverIDs) {
+ operations.push({
+ type: 'replace_keyserver',
+ payload: {
+ id: keyserverID,
+ keyserverInfo: {
+ ...state.keyserverInfos[keyserverID],
+ actualizedCalendarQuery: {
+ ...action.payload.calendarQuery,
+ filters: filterThreadIDsInFilterList(
+ action.payload.calendarQuery.filters,
+ (threadID: string) =>
+ extractKeyserverIDFromID(threadID) === keyserverID,
+ ),
+ },
+ },
+ },
+ });
+ }
+ return {
+ keyserverStore: processStoreOps(state, operations),
+ keyserverStoreOperations: operations,
+ };
}
return {
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,7 +1,6 @@
// @flow
import reduceCalendarFilters from './calendar-filters-reducer.js';
-import { reduceCalendarQuery } from './calendar-query-reducer.js';
import reduceCustomerServer from './custom-server-reducer.js';
import reduceDataLoaded from './data-loaded-reducer.js';
import { reduceDraftStore } from './draft-reducer.js';
@@ -176,10 +175,6 @@
state.notifPermissionAlertInfo,
action,
),
- 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
@@ -11,7 +11,6 @@
import type { UpdateCalendarQueryInput } from '../actions/entry-actions.js';
import { extractKeyserverIDFromID } from '../keyserver-conn/keyserver-call-utils.js';
import { filterThreadIDsInFilterList } from '../reducers/calendar-filters-reducer.js';
-import { connectionSelector } from '../selectors/keyserver-selectors.js';
import { timeUntilCalendarRangeExpiration } from '../selectors/nav-selectors.js';
import { useIsAppForegrounded } from '../shared/lifecycle-utils.js';
import type {
@@ -131,8 +130,11 @@
const ConnectedCalendarQueryHandler: React.ComponentType<BaseProps> =
React.memo<BaseProps>(function ConnectedCalendarQueryHandler(props) {
const { currentCalendarQuery, keyserverID } = props;
- const connection = useSelector(connectionSelector(keyserverID));
- invariant(connection, 'keyserver missing from keyserverStore');
+ const keyserverInfo = useSelector(
+ state => state.keyserverStore.keyserverInfos[keyserverID],
+ );
+ invariant(keyserverInfo, 'keyserver missing from keyserverStore');
+ const { connection, actualizedCalendarQuery } = keyserverInfo;
const lastUserInteractionCalendar = useSelector(
state => state.entryStore.lastUserInteractionCalendar,
);
@@ -140,7 +142,6 @@
const foreground = useIsAppForegrounded();
const callUpdateCalendarQuery = useUpdateCalendarQuery();
const dispatchActionPromise = useDispatchActionPromise();
- const calendarQuery = useSelector(state => state.actualizedCalendarQuery);
const getCurrentCalendarQuery = React.useCallback(() => {
const query = currentCalendarQuery();
@@ -158,7 +159,7 @@
<CalendarQueryHandler
{...props}
connection={connection}
- calendarQuery={calendarQuery}
+ calendarQuery={actualizedCalendarQuery}
lastUserInteractionCalendar={lastUserInteractionCalendar}
foreground={foreground}
updateCalendarQuery={callUpdateCalendarQuery}
diff --git a/lib/types/keyserver-types.js b/lib/types/keyserver-types.js
--- a/lib/types/keyserver-types.js
+++ b/lib/types/keyserver-types.js
@@ -3,6 +3,8 @@
import t, { type TInterface } from 'tcomb';
import type { PlatformDetails } from './device-types.js';
+import { calendarQueryValidator, type CalendarQuery } from './entry-types.js';
+import { defaultCalendarFilters } from './filter-types.js';
import {
type ConnectionInfo,
connectionInfoValidator,
@@ -19,6 +21,7 @@
+connection: ConnectionInfo,
+lastCommunicatedPlatformDetails: ?PlatformDetails,
+deviceToken: ?string,
+ +actualizedCalendarQuery: CalendarQuery,
};
const defaultKeyserverInfo: (
@@ -30,6 +33,11 @@
connection: defaultConnectionInfo,
lastCommunicatedPlatformDetails: null,
deviceToken: null,
+ actualizedCalendarQuery: {
+ startDate: '',
+ endDate: '',
+ filters: defaultCalendarFilters,
+ },
});
export type KeyserverInfos = { +[key: string]: KeyserverInfo };
@@ -61,6 +69,7 @@
connection: connectionInfoValidator,
lastCommunicatedPlatformDetails: t.maybe(tPlatformDetails),
deviceToken: t.maybe(t.String),
+ actualizedCalendarQuery: calendarQueryValidator,
});
export const keyserverStoreValidator: TInterface<KeyserverStore> =
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
@@ -36,7 +36,6 @@
FetchEntryInfosResult,
CalendarQueryUpdateResult,
CalendarQueryUpdateStartingPayload,
- CalendarQuery,
FetchRevisionsForEntryPayload,
} from './entry-types.js';
import type {
@@ -141,7 +140,6 @@
+loadingStatuses: { [key: string]: { [idx: number]: LoadingStatus } },
+calendarFilters: $ReadOnlyArray<CalendarFilter>,
+notifPermissionAlertInfo: NotifPermissionAlertInfo,
- +actualizedCalendarQuery: CalendarQuery,
+watchedThreadIDs: $ReadOnlyArray<string>,
+lifecycleState: LifecycleState,
+enabledApps: EnabledApps,
diff --git a/native/redux/persist.js b/native/redux/persist.js
--- a/native/redux/persist.js
+++ b/native/redux/persist.js
@@ -15,6 +15,7 @@
convertCalendarFilterToNewIDSchema,
convertConnectionInfoToNewIDSchema,
} from 'lib/_generated/migration-utils.js';
+import { extractKeyserverIDFromID } from 'lib/keyserver-conn/keyserver-call-utils.js';
import {
type ClientDBKeyserverStoreOperation,
keyserverStoreOpsHandlers,
@@ -38,6 +39,7 @@
convertUserInfosToReplaceUserOps,
userStoreOpsHandlers,
} from 'lib/ops/user-store-ops.js';
+import { filterThreadIDsInFilterList } from 'lib/reducers/calendar-filters-reducer.js';
import { highestLocalIDSelector } from 'lib/selectors/local-id-selectors.js';
import { createAsyncMigrate } from 'lib/shared/create-async-migrate.js';
import { inconsistencyResponsesToReports } from 'lib/shared/report-utils.js';
@@ -1080,6 +1082,46 @@
}
return state;
},
+ [63]: async (state: any) => {
+ const { actualizedCalendarQuery, ...rest } = state;
+ const operations: $ReadOnlyArray<ReplaceKeyserverOperation> = entries(
+ state.keyserverStore.keyserverInfos,
+ ).map(([id, keyserverInfo]) => ({
+ type: 'replace_keyserver',
+ payload: {
+ id,
+ keyserverInfo: {
+ ...keyserverInfo,
+ actualizedCalendarQuery: {
+ ...actualizedCalendarQuery,
+ filters: filterThreadIDsInFilterList(
+ actualizedCalendarQuery.filters,
+ (threadID: string) => extractKeyserverIDFromID(threadID) === id,
+ ),
+ },
+ },
+ },
+ }));
+ const dbOperations: $ReadOnlyArray<ClientDBKeyserverStoreOperation> =
+ keyserverStoreOpsHandlers.convertOpsToClientDBOps(operations);
+
+ const newState = {
+ ...rest,
+ keyserverStore: keyserverStoreOpsHandlers.processStoreOperations(
+ rest.keyserverStore,
+ operations,
+ ),
+ };
+ try {
+ await commCoreModule.processKeyserverStoreOperations(dbOperations);
+ } catch (exception) {
+ if (isTaskCancelledError(exception)) {
+ return newState;
+ }
+ return handleReduxMigrationFailure(newState);
+ }
+ return newState;
+ },
};
// After migration 31, we'll no longer want to persist `messageStore.messages`
diff --git a/web/database/queries/keyservers-queries.test.js b/web/database/queries/keyservers-queries.test.js
--- a/web/database/queries/keyservers-queries.test.js
+++ b/web/database/queries/keyservers-queries.test.js
@@ -4,6 +4,7 @@
convertKeyserverInfoToClientDBKeyserverInfo,
keyserverStoreOpsHandlers,
} from 'lib/ops/keyserver-store-ops.js';
+import { defaultCalendarFilters } from 'lib/types/filter-types.js';
import type { KeyserverInfo } from 'lib/types/keyserver-types.js';
import { defaultConnectionInfo } from 'lib/types/socket-types.js';
@@ -23,6 +24,11 @@
},
deviceToken: 'token',
lastCommunicatedPlatformDetails: null,
+ actualizedCalendarQuery: {
+ startDate: '',
+ endDate: '',
+ filters: defaultCalendarFilters,
+ },
};
const TEST_KEYSERVER_2: KeyserverInfo = {
cookie: 'testCookie2',
@@ -33,6 +39,11 @@
},
deviceToken: 'token',
lastCommunicatedPlatformDetails: null,
+ actualizedCalendarQuery: {
+ startDate: '',
+ endDate: '',
+ filters: defaultCalendarFilters,
+ },
};
describe('Keyserver Store queries', () => {
diff --git a/web/redux/action-types.js b/web/redux/action-types.js
--- a/web/redux/action-types.js
+++ b/web/redux/action-types.js
@@ -2,7 +2,6 @@
import { extractKeyserverIDFromID } from 'lib/keyserver-conn/keyserver-call-utils.js';
import type { CallKeyserverEndpoint } from 'lib/keyserver-conn/keyserver-conn-types.js';
-import { defaultCalendarFilters } from 'lib/types/filter-types.js';
import type {
WebInitialKeyserverInfo,
ClientWebInitialReduxStateResponse,
@@ -92,11 +91,6 @@
} = responses[ashoatKeyserverID];
const dataLoaded = currentUserInfo && !currentUserInfo.anonymous;
- const actualizedCalendarQuery = {
- startDate: navInfo.startDate,
- endDate: navInfo.endDate,
- filters: defaultCalendarFilters,
- };
const entryStore = {
daysToEntries: {},
@@ -169,7 +163,6 @@
entryStore,
threadStore,
userInfos,
- actualizedCalendarQuery,
messageStore,
dataLoaded,
pushApiPublicKey,
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
@@ -63,11 +63,6 @@
inviteLinksStore: {
links: {},
},
- actualizedCalendarQuery: {
- startDate: '',
- endDate: '',
- filters: defaultCalendarFilters,
- },
communityPickerStore: { chat: null, calendar: null },
keyserverStore: {
keyserverInfos: {
diff --git a/web/redux/persist.js b/web/redux/persist.js
--- a/web/redux/persist.js
+++ b/web/redux/persist.js
@@ -5,11 +5,13 @@
import storage from 'redux-persist/es/storage/index.js';
import type { PersistConfig } from 'redux-persist/src/types.js';
+import { extractKeyserverIDFromID } from 'lib/keyserver-conn/keyserver-call-utils.js';
import {
type ClientDBKeyserverStoreOperation,
keyserverStoreOpsHandlers,
type ReplaceKeyserverOperation,
} from 'lib/ops/keyserver-store-ops.js';
+import { filterThreadIDsInFilterList } from 'lib/reducers/calendar-filters-reducer.js';
import {
createAsyncMigrate,
type StorageMigrationFunction,
@@ -261,6 +263,54 @@
return handleReduxMigrationFailure(state);
}
},
+ [12]: async (state: any) => {
+ const { actualizedCalendarQuery, ...rest } = state;
+ const databaseModule = await getDatabaseModule();
+ const operations: $ReadOnlyArray<ReplaceKeyserverOperation> = entries(
+ state.keyserverStore.keyserverInfos,
+ ).map(([id, keyserverInfo]) => ({
+ type: 'replace_keyserver',
+ payload: {
+ id,
+ keyserverInfo: {
+ ...keyserverInfo,
+ actualizedCalendarQuery: {
+ ...actualizedCalendarQuery,
+ filters: filterThreadIDsInFilterList(
+ actualizedCalendarQuery.filters,
+ (threadID: string) => extractKeyserverIDFromID(threadID) === id,
+ ),
+ },
+ },
+ },
+ }));
+ const dbOperations: $ReadOnlyArray<ClientDBKeyserverStoreOperation> =
+ keyserverStoreOpsHandlers.convertOpsToClientDBOps(operations);
+
+ const newState = {
+ ...rest,
+ keyserverStore: keyserverStoreOpsHandlers.processStoreOperations(
+ rest.keyserverStore,
+ operations,
+ ),
+ };
+
+ const isDatabaseSupported = await databaseModule.isDatabaseSupported();
+ if (!isDatabaseSupported) {
+ return newState;
+ }
+
+ try {
+ await databaseModule.schedule({
+ type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
+ storeOperations: { keyserverStoreOperations: dbOperations },
+ });
+ return newState;
+ } catch (e) {
+ console.log(e);
+ return handleReduxMigrationFailure(newState);
+ }
+ },
};
const rootKey = 'root';
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
@@ -29,7 +29,7 @@
import type { CryptoStore } from 'lib/types/crypto-types.js';
import type { DraftStore } from 'lib/types/draft-types.js';
import type { EnabledApps } from 'lib/types/enabled-apps.js';
-import type { EntryStore, CalendarQuery } from 'lib/types/entry-types.js';
+import type { EntryStore } from 'lib/types/entry-types.js';
import { type CalendarFilter } from 'lib/types/filter-types.js';
import type { IntegrityStore } from 'lib/types/integrity-types.js';
import type { KeyserverStore } from 'lib/types/keyserver-types.js';
@@ -98,7 +98,6 @@
+communityPickerStore: CommunityPickerStore,
+windowDimensions: WindowDimensions,
+notifPermissionAlertInfo: NotifPermissionAlertInfo,
- +actualizedCalendarQuery: CalendarQuery,
+watchedThreadIDs: $ReadOnlyArray<string>,
+lifecycleState: LifecycleState,
+enabledApps: EnabledApps,
diff --git a/web/types/redux-types.js b/web/types/redux-types.js
--- a/web/types/redux-types.js
+++ b/web/types/redux-types.js
@@ -1,6 +1,6 @@
// @flow
-import type { EntryStore, CalendarQuery } from 'lib/types/entry-types.js';
+import type { EntryStore } from 'lib/types/entry-types.js';
import type { InviteLinksStore } from 'lib/types/link-types.js';
import type { MessageStore } from 'lib/types/message-types.js';
import type { WebNavInfo } from 'lib/types/nav-types.js';
@@ -20,7 +20,6 @@
+commServicesAccessToken: null,
+inviteLinksStore: InviteLinksStore,
+dataLoaded: boolean,
- +actualizedCalendarQuery: CalendarQuery,
+keyserverInfos: { +[keyserverID: string]: WebInitialKeyserverInfo },
};

File Metadata

Mime Type
text/plain
Expires
Fri, Jan 10, 1:08 AM (4 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2842537
Default Alt Text
D11144.id37438.diff (21 KB)

Event Timeline