Page MenuHomePhabricator

D12384.id41227.diff
No OneTemporary

D12384.id41227.diff

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
@@ -86,7 +86,12 @@
// Only allow checkpoints to increase if we are connected
// or if the action is a STATE_SYNC
const { messageStoreOperations, messageStore: reducedMessageStore } =
- reduceMessageStore(state.messageStore, action, threadInfos);
+ reduceMessageStore(
+ state.messageStore,
+ action,
+ threadInfos,
+ onStateDifferenceForStaff,
+ );
let messageStore = reducedMessageStore;
let { keyserverStore, keyserverStoreOperations } = reduceKeyserverStore(
diff --git a/lib/reducers/message-reducer.js b/lib/reducers/message-reducer.js
--- a/lib/reducers/message-reducer.js
+++ b/lib/reducers/message-reducer.js
@@ -109,7 +109,12 @@
type ClientUpdateInfo,
processUpdatesActionType,
} from '../types/update-types.js';
-import { translateClientDBThreadMessageInfos } from '../utils/message-ops-utils.js';
+import { getMessageForException } from '../utils/errors.js';
+import {
+ translateClientDBThreadMessageInfos,
+ translateClientDBLocalMessageInfos,
+} from '../utils/message-ops-utils.js';
+import { assertObjectsAreEqual } from '../utils/objects.js';
const _mapValuesWithKeys = _mapValues.convert({ cap: false });
@@ -142,6 +147,31 @@
);
}
+function assertMessageStoreLocalMessageInfosAreEqual(
+ processedMessageStore: MessageStore,
+ expectedMessageStore: MessageStore,
+ location: string,
+ onStateDifference?: (message: string) => mixed,
+) {
+ try {
+ assertObjectsAreEqual(
+ processedMessageStore.local,
+ expectedMessageStore.local,
+ `MessageStore.local - ${location}`,
+ );
+ } catch (e) {
+ console.log(
+ 'Error processing MessageStore local ops',
+ processedMessageStore.local,
+ expectedMessageStore.local,
+ );
+ const message = `Error processing MessageStore local ops ${
+ getMessageForException(e) ?? '{no exception message}'
+ }`;
+ onStateDifference?.(message);
+ }
+}
+
const newThread = (): ThreadMessageInfo => ({
messageIDs: [],
startReached: false,
@@ -727,6 +757,7 @@
messageStore: MessageStore,
action: BaseAction,
newThreadInfos: RawThreadInfos,
+ onStateDifference?: (message: string) => mixed,
): ReduceMessageStoreResult {
if (
action.type === legacyLogInActionTypes.success ||
@@ -1595,6 +1626,21 @@
action.payload.messageStoreThreads ?? [],
);
+ const actionPayloadMessageStoreLocalMessageInfos =
+ translateClientDBLocalMessageInfos(
+ action.payload.messageStoreLocalMessageInfos ?? [],
+ );
+
+ assertMessageStoreLocalMessageInfosAreEqual(
+ {
+ ...messageStore,
+ local: actionPayloadMessageStoreLocalMessageInfos,
+ },
+ messageStore,
+ action.type,
+ onStateDifference,
+ );
+
const newThreads: {
[threadID: string]: ThreadMessageInfo,
} = { ...messageStore.threads };
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
@@ -298,7 +298,7 @@
auxUserInfos: {},
threadActivityStore: {},
entries: {},
- messageStoreLocalMessageInfos: {},
+ messageStoreLocalMessageInfos: [],
},
},
{
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
@@ -11,7 +11,6 @@
import type { ThreadHashes } from './integrity-types.js';
import type { KeyserverInfos } from './keyserver-types.js';
import type {
- MessageStoreLocalMessageInfos,
ClientDBMessageInfo,
ClientDBThreadMessageInfo,
ClientDBLocalMessageInfo,
@@ -139,5 +138,5 @@
+auxUserInfos: ?AuxUserInfos,
+threadActivityStore: ?ThreadActivityStore,
+entries: ?RawEntryInfos,
- +messageStoreLocalMessageInfos: ?MessageStoreLocalMessageInfos,
+ +messageStoreLocalMessageInfos: ?$ReadOnlyArray<ClientDBLocalMessageInfo>,
};
diff --git a/lib/utils/message-ops-utils.js b/lib/utils/message-ops-utils.js
--- a/lib/utils/message-ops-utils.js
+++ b/lib/utils/message-ops-utils.js
@@ -25,6 +25,8 @@
type RawMessageInfo,
type ClientDBThreadMessageInfo,
type ThreadMessageInfo,
+ type ClientDBLocalMessageInfo,
+ type MessageStoreLocalMessageInfos,
} from '../types/message-types.js';
import type { MediaMessageServerDBContent } from '../types/messages/media.js';
@@ -272,6 +274,19 @@
};
}
+function translateClientDBLocalMessageInfos(
+ clientDBLocalMessageInfos: $ReadOnlyArray<ClientDBLocalMessageInfo>,
+): MessageStoreLocalMessageInfos {
+ return Object.fromEntries(
+ clientDBLocalMessageInfos.map(
+ (localMessageInfo: ClientDBLocalMessageInfo) => [
+ localMessageInfo.id,
+ JSON.parse(localMessageInfo.localMessageInfo),
+ ],
+ ),
+ );
+}
+
function getPinnedContentFromClientDBMessageInfo(
clientDBMessageInfo: ClientDBMessageInfo,
): string {
@@ -295,4 +310,5 @@
getPinnedContentFromClientDBMessageInfo,
translateClientDBThreadMessageInfos,
translateThreadMessageInfoToClientDBThreadMessageInfo,
+ translateClientDBLocalMessageInfos,
};
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
@@ -244,6 +244,7 @@
auxUserInfos,
threadActivityEntries,
entries,
+ messageStoreLocalMessageInfos,
} = await commCoreModule.getClientDBStore();
const threadInfosFromDB =
threadStoreOpsHandlers.translateClientDBData(threads);
@@ -285,6 +286,7 @@
auxUserInfos: auxUserInfosFromDB,
threadActivityStore: threadActivityStoreFromDB,
entries: entriesFromDB,
+ messageStoreLocalMessageInfos,
},
});
} catch (setStoreException) {

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 7:01 AM (45 m, 50 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675806
Default Alt Text
D12384.id41227.diff (5 KB)

Event Timeline