Page MenuHomePhabricator

D8385.diff
No OneTemporary

D8385.diff

diff --git a/lib/utils/migration-utils.js b/lib/utils/migration-utils.js
--- a/lib/utils/migration-utils.js
+++ b/lib/utils/migration-utils.js
@@ -1,7 +1,9 @@
// @flow
+import type { TranslatedThreadMessageInfos } from './message-ops-utils.js';
import { entries } from './objects.js';
import { keyserverPrefixID } from './validation-utils.js';
+import { convertRawThreadInfoToNewIDSchema } from '../_generated/migration-utils.js';
import {
parsePendingThreadID,
getPendingThreadID,
@@ -12,6 +14,7 @@
ClientDBDraftStoreOperation,
DraftStore,
} from '../types/draft-types';
+import type { ThreadStoreThreadInfos } from '../types/thread-types.js';
function convertDraftKeyToNewIDSchema(key: string): string {
const threadID = key.slice(0, -draftKeySuffix.length);
@@ -61,8 +64,32 @@
return [{ type: 'remove_all' }, ...operations];
}
+function convertMessageStoreThreadsToNewIDSchema(
+ messageStoreThreads: TranslatedThreadMessageInfos,
+): TranslatedThreadMessageInfos {
+ return Object.fromEntries(
+ entries(messageStoreThreads).map(([id, translatedThreadMessageInfo]) => [
+ `${keyserverPrefixID}|` + id,
+ translatedThreadMessageInfo,
+ ]),
+ );
+}
+
+function convertThreadStoreThreadInfosToNewIDSchema(
+ threadStoreThreadInfos: ThreadStoreThreadInfos,
+): ThreadStoreThreadInfos {
+ return Object.fromEntries(
+ entries(threadStoreThreadInfos).map(([id, threadInfo]) => [
+ `${keyserverPrefixID}|` + id,
+ convertRawThreadInfoToNewIDSchema(threadInfo),
+ ]),
+ );
+}
+
export {
convertDraftKeyToNewIDSchema,
convertDraftStoreToNewIDSchema,
generateIDSchemaMigrationOpsForDrafts,
+ convertMessageStoreThreadsToNewIDSchema,
+ convertThreadStoreThreadInfosToNewIDSchema,
};
diff --git a/native/redux/persist.js b/native/redux/persist.js
--- a/native/redux/persist.js
+++ b/native/redux/persist.js
@@ -7,6 +7,14 @@
import { createTransform } from 'redux-persist';
import type { Transform } from 'redux-persist/es/types.js';
+import {
+ convertEntryStoreToNewIDSchema,
+ convertInviteLinksStoreToNewIDSchema,
+ convertMessageStoreToNewIDSchema,
+ convertRawMessageInfoToNewIDSchema,
+ convertCalendarFilterToNewIDSchema,
+ convertConnectionInfoToNewIDSchema,
+} from 'lib/_generated/migration-utils.js';
import {
type ReportStoreOperation,
type ClientDBReportStoreOperation,
@@ -46,6 +54,11 @@
translateClientDBMessageInfoToRawMessageInfo,
translateRawMessageInfoToClientDBMessageInfo,
} from 'lib/utils/message-ops-utils.js';
+import {
+ generateIDSchemaMigrationOpsForDrafts,
+ convertMessageStoreThreadsToNewIDSchema,
+ convertThreadStoreThreadInfosToNewIDSchema,
+} from 'lib/utils/migration-utils.js';
import { defaultNotifPermissionAlertInfo } from 'lib/utils/push-alerts.js';
import {
convertClientDBThreadInfoToRawThreadInfo,
@@ -53,8 +66,14 @@
convertThreadStoreOperationsToClientDBOperations,
} from 'lib/utils/thread-ops-utils.js';
import { getUUID } from 'lib/utils/uuid.js';
+import { keyserverPrefixID } from 'lib/utils/validation-utils.js';
-import { updateClientDBThreadStoreThreadInfos } from './client-db-utils.js';
+import {
+ updateClientDBThreadStoreThreadInfos,
+ createUpdateDBOpsForThreadStoreThreadInfos,
+ createUpdateDBOpsForMessageStoreMessages,
+ createUpdateDBOpsForMessageStoreThreads,
+} from './client-db-utils.js';
import { migrateThreadStoreForEditThreadPermissions } from './edit-thread-permission-migration.js';
import { persistMigrationForManagePinsThreadPermission } from './manage-pins-permission-migration.js';
import type { AppState } from './state-types.js';
@@ -577,6 +596,58 @@
}
return state;
},
+ [43]: async (state: AppState) => {
+ const { messages, drafts, threads, messageStoreThreads } =
+ await commCoreModule.getClientDBStore();
+
+ const messageStoreThreadsOperations =
+ createUpdateDBOpsForMessageStoreThreads(
+ messageStoreThreads,
+ convertMessageStoreThreadsToNewIDSchema,
+ );
+
+ const messageStoreMessagesOperations =
+ createUpdateDBOpsForMessageStoreMessages(messages, messageInfos =>
+ messageInfos.map(convertRawMessageInfoToNewIDSchema),
+ );
+
+ const threadOperations = createUpdateDBOpsForThreadStoreThreadInfos(
+ threads,
+ convertThreadStoreThreadInfosToNewIDSchema,
+ );
+
+ const draftOperations = generateIDSchemaMigrationOpsForDrafts(drafts);
+
+ try {
+ await Promise.all([
+ commCoreModule.processMessageStoreOperations([
+ ...messageStoreMessagesOperations,
+ ...messageStoreThreadsOperations,
+ ]),
+ commCoreModule.processThreadStoreOperations(threadOperations),
+ commCoreModule.processDraftStoreOperations(draftOperations),
+ ]);
+ } catch (exception) {
+ console.log(exception);
+ return { ...state, cookie: null };
+ }
+
+ return {
+ ...state,
+ entryStore: convertEntryStoreToNewIDSchema(state.entryStore),
+ messageStore: convertMessageStoreToNewIDSchema(state.messageStore),
+ calendarFilters: state.calendarFilters.map(
+ convertCalendarFilterToNewIDSchema,
+ ),
+ connection: convertConnectionInfoToNewIDSchema(state.connection),
+ watchedThreadIDs: state.watchedThreadIDs.map(
+ id => `${keyserverPrefixID}|${id}`,
+ ),
+ inviteLinksStore: convertInviteLinksStoreToNewIDSchema(
+ state.inviteLinksStore,
+ ),
+ };
+ },
};
// After migration 31, we'll no longer want to persist `messageStore.messages`

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 8:51 PM (17 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2682909
Default Alt Text
D8385.diff (5 KB)

Event Timeline