Page MenuHomePhabricator

D12147.id40524.diff
No OneTemporary

D12147.id40524.diff

diff --git a/lib/reducers/entry-reducer.js b/lib/reducers/entry-reducer.js
--- a/lib/reducers/entry-reducer.js
+++ b/lib/reducers/entry-reducer.js
@@ -13,6 +13,7 @@
import _sortBy from 'lodash/fp/sortBy.js';
import _union from 'lodash/fp/union.js';
+import { setClientDBStoreActionType } from '../actions/client-db-store-actions.js';
import {
fetchEntriesActionTypes,
updateCalendarQueryActionTypes,
@@ -45,6 +46,7 @@
import { stateSyncSpecs } from '../shared/state-sync/state-sync-specs.js';
import { threadInFilterList } from '../shared/thread-utils.js';
import { updateSpecs } from '../shared/updates/update-specs.js';
+import { isWebPlatform } from '../types/device-types.js';
import type { RawEntryInfo, EntryStore } from '../types/entry-types.js';
import type { BaseAction } from '../types/redux-types.js';
import { type ClientEntryInconsistencyReportCreationRequest } from '../types/report-types.js';
@@ -62,10 +64,37 @@
processUpdatesActionType,
} from '../types/update-types.js';
import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js';
+import { getConfig } from '../utils/config.js';
import { dateString } from '../utils/date-utils.js';
-import { values } from '../utils/objects.js';
+import { getMessageForException } from '../utils/errors.js';
+import { assertObjectsAreEqual, values } from '../utils/objects.js';
import { relyingOnAuthoritativeKeyserver } from '../utils/services-utils.js';
+function assertEntryStoresAreEqual(
+ processedEntryStore: EntryStore,
+ expectedEntryStore: EntryStore,
+ location: string,
+ onStateDifference?: (message: string) => mixed,
+) {
+ try {
+ assertObjectsAreEqual(
+ processedEntryStore,
+ expectedEntryStore,
+ `EntryStore - ${location}`,
+ );
+ } catch (e) {
+ console.log(
+ 'Error processing EntryStore ops',
+ processedEntryStore,
+ expectedEntryStore,
+ );
+ const message = `Error processing EntryStore ops ${
+ getMessageForException(e) ?? '{no exception message}'
+ }`;
+ onStateDifference?.(message);
+ }
+}
+
function daysToEntriesFromEntryInfos(
entryInfos: $ReadOnlyArray<RawEntryInfo>,
): { [day: string]: string[] } {
@@ -167,6 +196,7 @@
entryStore: EntryStore,
action: BaseAction,
newThreadInfos: RawThreadInfos,
+ onStateDifference?: (message: string) => mixed,
): {
+entryStore: EntryStore,
+entryStoreOperations: $ReadOnlyArray<EntryStoreOperation>,
@@ -683,6 +713,26 @@
entryStoreOperations: [],
reportCreationRequests: newInconsistencies,
};
+ } else if (action.type === setClientDBStoreActionType) {
+ const entryInfosFromDB = action.payload.entries ?? {};
+ const newStore = {
+ entryInfos: entryInfosFromDB,
+ daysToEntries: daysToEntriesFromEntryInfos(values(entryInfosFromDB)),
+ lastUserInteractionCalendar,
+ };
+ if (!isWebPlatform(getConfig().platformDetails.platform)) {
+ assertEntryStoresAreEqual(
+ newStore,
+ entryStore,
+ action.type,
+ onStateDifference,
+ );
+ }
+ return {
+ entryStore,
+ entryStoreOperations: [],
+ reportCreationRequests: [],
+ };
}
return {
entryStore,
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
@@ -55,7 +55,7 @@
const { threadInfos } = threadStore;
const { entryStore, reportCreationRequests: newEntryInconsistencies } =
- reduceEntryInfos(state.entryStore, action, threadInfos);
+ reduceEntryInfos(state.entryStore, action, threadInfos, onStateDifference);
const onStateDifferenceForStaff = (message: string) => {
const isCurrentUserStaff = state.currentUserInfo?.id

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 29, 1:47 AM (8 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2730118
Default Alt Text
D12147.id40524.diff (3 KB)

Event Timeline