Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3179847
D11887.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D11887.diff
View Options
diff --git a/native/redux/unshim-utils.js b/native/redux/unshim-utils.js
--- a/native/redux/unshim-utils.js
+++ b/native/redux/unshim-utils.js
@@ -1,17 +1,24 @@
// @flow
-import type { ClientDBMessageStoreOperation } from 'lib/ops/message-store-ops.js';
+import {
+ type MessageStoreOperation,
+ messageStoreOpsHandlers,
+} from 'lib/ops/message-store-ops.js';
+import { messageID } from 'lib/shared/message-utils.js';
import { unshimFunc } from 'lib/shared/unshim-utils.js';
import { type MessageType } from 'lib/types/message-types-enum.js';
-import type { ClientDBMessageInfo } from 'lib/types/message-types.js';
-import {
- translateClientDBMessageInfoToRawMessageInfo,
- translateRawMessageInfoToClientDBMessageInfo,
-} from 'lib/utils/message-ops-utils.js';
+import type { RawMessageInfo } from 'lib/types/message-types.js';
+import { translateClientDBMessageInfoToRawMessageInfo } from 'lib/utils/message-ops-utils.js';
+import { handleReduxMigrationFailure } from './handle-redux-migration-failure.js';
import type { AppState } from './state-types.js';
import { commCoreModule } from '../native-modules.js';
+const {
+ processStoreOperations: processMessageStoreOperations,
+ convertOpsToClientDBOps: convertMessageOpsToClientDBOps,
+} = messageStoreOpsHandlers;
+
function unshimClientDB(
state: AppState,
unshimTypes: $ReadOnlyArray<MessageType>,
@@ -29,41 +36,38 @@
unshimFunc(messageInfo, new Set(unshimTypes)),
);
- // 4. Translate unshimmed `RawMessageInfo`s back to `ClientDBMessageInfo`s.
- const unshimmedClientDBMessageInfos = unshimmedRawMessageInfos.map(
- translateRawMessageInfoToClientDBMessageInfo,
- );
-
- // 5. Construct `ClientDBMessageStoreOperation`s to clear SQLite `messages`
- // table and repopulate with unshimmed `ClientDBMessageInfo`s.
- const operations: $ReadOnlyArray<ClientDBMessageStoreOperation> = [
+ // 4. Construct `MessageStoreOperation`s to clear SQLite `messages` table and
+ // repopulate with unshimmed `RawMessageInfo`s.
+ const operations: $ReadOnlyArray<MessageStoreOperation> = [
{
type: 'remove_all',
},
- ...unshimmedClientDBMessageInfos.map((message: ClientDBMessageInfo) => ({
+ ...unshimmedRawMessageInfos.map((message: RawMessageInfo) => ({
type: 'replace',
- payload: message,
+ payload: { id: messageID(message), messageInfo: message },
})),
];
- // 6. Try processing `ClientDBMessageStoreOperation`s and log out if
+ // 5. Try processing `ClientDBMessageStoreOperation`s and log out if
// `processMessageStoreOperationsSync(...)` throws an exception.
try {
- commCoreModule.processMessageStoreOperationsSync(operations);
- } catch (exception) {
- console.log(exception);
- const keyserverInfos = { ...state.keyserverStore.keyserverInfos };
- for (const key in keyserverInfos) {
- keyserverInfos[key] = { ...keyserverInfos[key], cookie: null };
- }
- const keyserverStore = { ...state.keyserverStore, keyserverInfos };
+ const convertedMessageStoreOperations =
+ convertMessageOpsToClientDBOps(operations);
+ commCoreModule.processMessageStoreOperationsSync(
+ convertedMessageStoreOperations,
+ );
+ const processedMessageStore = processMessageStoreOperations(
+ state.messageStore,
+ operations,
+ );
return {
...state,
- keyserverStore,
+ messageStore: processedMessageStore,
};
+ } catch (exception) {
+ console.log(exception);
+ return handleReduxMigrationFailure(state);
}
-
- return state;
}
export { unshimClientDB };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 9, 3:40 AM (22 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2448292
Default Alt Text
D11887.diff (3 KB)
Attached To
Mode
D11887: [native] Update unshimClientDB to reflect best practices
Attached
Detach File
Event Timeline
Log In to Comment