diff --git a/lib/reducers/integrity-reducer.js b/lib/reducers/integrity-reducer.js --- a/lib/reducers/integrity-reducer.js +++ b/lib/reducers/integrity-reducer.js @@ -18,13 +18,40 @@ import type { RawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import type { BaseAction } from '../types/redux-types.js'; import { fullStateSyncActionType } from '../types/socket-types.js'; -import { hash } from '../utils/objects.js'; +import { getMessageForException } from '../utils/errors.js'; +import { assertObjectsAreEqual, hash } from '../utils/objects.js'; const { processStoreOperations: processStoreOps } = integrityStoreOpsHandlers; +function assertIntegrityStoresAreEqual( + processedIntegrityStore: ThreadHashes, + expectedIntegrityStore: ThreadHashes, + location: string, + onStateDifference?: (message: string) => mixed, +) { + try { + assertObjectsAreEqual( + processedIntegrityStore, + expectedIntegrityStore, + `IntegrityInfos - ${location}`, + ); + } catch (e) { + console.log( + 'Error processing IntegrityStore ops', + processedIntegrityStore, + expectedIntegrityStore, + ); + const message = `Error processing IntegrityStore ops ${ + getMessageForException(e) ?? '{no exception message}' + }`; + onStateDifference?.(message); + } +} + function reduceIntegrityStore( state: IntegrityStore, action: BaseAction, + onStateDifference?: (message: string) => mixed, threadInfos: { +[string]: RawThreadInfo, }, @@ -76,7 +103,19 @@ }, integrityStoreOperations: [], }; + } else if (action.type === setClientDBStoreActionType) { + assertIntegrityStoresAreEqual( + action.payload.threadHashes ?? {}, + state.threadHashes, + action.type, + onStateDifference, + ); + return { + integrityStore: state, + integrityStoreOperations: [], + }; } + let newState = state; const integrityOperations: IntegrityStoreOperation[] = []; if (action.type === updateIntegrityStoreActionType) { 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 @@ -164,6 +164,7 @@ const { integrityStore, integrityStoreOperations } = reduceIntegrityStore( state.integrityStore, action, + onStateDifferenceForStaff, threadInfos, threadStoreOperations, ); diff --git a/lib/reducers/message-reducer.test.js b/lib/reducers/message-reducer.test.js --- a/lib/reducers/message-reducer.test.js +++ b/lib/reducers/message-reducer.test.js @@ -293,6 +293,7 @@ users: {}, keyserverInfos: {}, communityInfos: {}, + threadHashes: {}, }, }, { diff --git a/lib/types/store-ops-types.js b/lib/types/store-ops-types.js --- a/lib/types/store-ops-types.js +++ b/lib/types/store-ops-types.js @@ -6,6 +6,7 @@ ClientDBDraftStoreOperation, ClientDBDraftInfo, } from './draft-types.js'; +import type { ThreadHashes } from './integrity-types.js'; import type { KeyserverInfos } from './keyserver-types.js'; import type { ClientDBMessageInfo, @@ -90,4 +91,5 @@ +users: ?UserInfos, +keyserverInfos: ?KeyserverInfos, +communityInfos: ?CommunityInfos, + +threadHashes: ?ThreadHashes, }; diff --git a/native/data/sqlite-data-handler.js b/native/data/sqlite-data-handler.js --- a/native/data/sqlite-data-handler.js +++ b/native/data/sqlite-data-handler.js @@ -8,6 +8,7 @@ import type { CallKeyserverEndpoint } from 'lib/keyserver-conn/keyserver-conn-types.js'; import { useKeyserverRecoveryLogIn } from 'lib/keyserver-conn/recovery-utils.js'; import { communityStoreOpsHandlers } from 'lib/ops/community-store-ops.js'; +import { integrityStoreOpsHandlers } from 'lib/ops/integrity-store-ops.js'; import { keyserverStoreOpsHandlers } from 'lib/ops/keyserver-store-ops.js'; import { reportStoreOpsHandlers } from 'lib/ops/report-store-ops.js'; import { threadStoreOpsHandlers } from 'lib/ops/thread-store-ops.js'; @@ -206,6 +207,7 @@ users, keyservers, communities, + integrityThreadHashes, } = await commCoreModule.getClientDBStore(); const threadInfosFromDB = threadStoreOpsHandlers.translateClientDBData(threads); @@ -216,6 +218,10 @@ keyserverStoreOpsHandlers.translateClientDBData(keyservers); const communityInfosFromDB = communityStoreOpsHandlers.translateClientDBData(communities); + const threadHashesFromDB = + integrityStoreOpsHandlers.translateClientDBData( + integrityThreadHashes, + ); dispatch({ type: setClientDBStoreActionType, @@ -229,6 +235,7 @@ users: usersFromDB, keyserverInfos: keyserverInfosFromDB, communities: communityInfosFromDB, + threadHashes: threadHashesFromDB, }, }); } catch (setStoreException) { diff --git a/web/shared-worker/utils/store.js b/web/shared-worker/utils/store.js --- a/web/shared-worker/utils/store.js +++ b/web/shared-worker/utils/store.js @@ -27,6 +27,7 @@ users: null, keyserverInfos: defaultWebState.keyserverStore.keyserverInfos, communityInfos: null, + threadHashes: null, }; const data = await sharedWorker.schedule({ type: workerRequestMessageTypes.GET_CLIENT_STORE, @@ -69,6 +70,14 @@ ), }; } + if (data?.store?.integrityThreadHashes) { + result = { + ...result, + threadHashes: integrityStoreOpsHandlers.translateClientDBData( + data.store.integrityThreadHashes, + ), + }; + } return result; }