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,5 +1,7 @@ // @flow +import invariant from 'invariant'; + import type { TranslatedThreadMessageInfos } from './message-ops-utils.js'; import { entries } from './objects.js'; import { ashoatKeyserverID } from './validation-utils.js'; @@ -23,7 +25,7 @@ threadPermissionPropagationPrefixes, threadPermissionFilterPrefixes, } from '../types/thread-permission-types.js'; -import type { ThreadStoreThreadInfos } from '../types/thread-types.js'; +import type { RawThreadInfos } from '../types/thread-types.js'; function convertDraftKeyToNewIDSchema(key: string): string { const threadID = key.slice(0, -draftKeySuffix.length); @@ -67,13 +69,19 @@ } function convertThreadStoreThreadInfosToNewIDSchema( - threadStoreThreadInfos: ThreadStoreThreadInfos, -): ThreadStoreThreadInfos { + threadStoreThreadInfos: RawThreadInfos, +): RawThreadInfos { return Object.fromEntries( - entries(threadStoreThreadInfos).map(([id, threadInfo]) => [ - `${ashoatKeyserverID}|` + id, - convertRawThreadInfoToNewIDSchema(threadInfo), - ]), + entries(threadStoreThreadInfos).map(([id, threadInfo]) => { + invariant( + !threadInfo.minimallyEncoded, + `threadInfo during ID schema migration shouldn't be minimallyEncoded`, + ); + return [ + `${ashoatKeyserverID}|` + id, + convertRawThreadInfoToNewIDSchema(threadInfo), + ]; + }), ); }