Page MenuHomePhabricator

D11057.id37042.diff
No OneTemporary

D11057.id37042.diff

diff --git a/native/redux/client-db-utils.js b/native/redux/client-db-utils.js
--- a/native/redux/client-db-utils.js
+++ b/native/redux/client-db-utils.js
@@ -1,107 +1,19 @@
// @flow
import type { ClientDBMessageStoreOperation } from 'lib/ops/message-store-ops.js';
-import type { ClientDBThreadStoreOperation } from 'lib/ops/thread-store-ops.js';
import type {
- RawMessageInfo,
ClientDBMessageInfo,
ClientDBThreadMessageInfo,
+ RawMessageInfo,
} from 'lib/types/message-types.js';
-import type { RawThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
-import type {
- ClientDBThreadInfo,
- LegacyRawThreadInfo,
- MixedRawThreadInfos,
-} from 'lib/types/thread-types.js';
import {
translateClientDBMessageInfoToRawMessageInfo,
- translateRawMessageInfoToClientDBMessageInfo,
translateClientDBThreadMessageInfos,
- translateThreadMessageInfoToClientDBThreadMessageInfo,
type TranslatedThreadMessageInfos,
+ translateRawMessageInfoToClientDBMessageInfo,
+ translateThreadMessageInfoToClientDBThreadMessageInfo,
} from 'lib/utils/message-ops-utils.js';
-import { values, entries } from 'lib/utils/objects.js';
-import {
- convertRawThreadInfoToClientDBThreadInfo,
- deprecatedConvertClientDBThreadInfoToRawThreadInfo,
-} from 'lib/utils/thread-ops-utils.js';
-
-import type { AppState } from './state-types.js';
-import { commCoreModule } from '../native-modules.js';
-
-function updateClientDBThreadStoreThreadInfos(
- state: AppState,
- migrationFunc: MixedRawThreadInfos => MixedRawThreadInfos,
- handleMigrationFailure?: AppState => AppState,
-): AppState {
- // Get threads from SQLite `threads` table.
- const clientDBThreadInfos = commCoreModule.getAllThreadsSync();
-
- const operations = createUpdateDBOpsForThreadStoreThreadInfos(
- clientDBThreadInfos,
- migrationFunc,
- );
-
- // Try processing `ClientDBThreadStoreOperation`s and log out if
- // `processThreadStoreOperationsSync(...)` throws an exception.
- try {
- commCoreModule.processThreadStoreOperationsSync(operations);
- } catch (exception) {
- console.log(exception);
- if (handleMigrationFailure) {
- return handleMigrationFailure(state);
- }
- return ({ ...state, cookie: null }: any);
- }
-
- return state;
-}
-
-function createUpdateDBOpsForThreadStoreThreadInfos(
- clientDBThreadInfos: $ReadOnlyArray<ClientDBThreadInfo>,
- migrationFunc: MixedRawThreadInfos => MixedRawThreadInfos,
-): $ReadOnlyArray<ClientDBThreadStoreOperation> {
- // Translate `ClientDBThreadInfo`s to `RawThreadInfo`s.
- const rawThreadInfos = clientDBThreadInfos.map(
- deprecatedConvertClientDBThreadInfoToRawThreadInfo,
- );
-
- // Convert `rawThreadInfo`s to a map of `threadID` => `threadInfo`.
- const threadIDToThreadInfo = rawThreadInfos.reduce(
- (
- acc: { [string]: LegacyRawThreadInfo | RawThreadInfo },
- threadInfo: LegacyRawThreadInfo | RawThreadInfo,
- ) => {
- acc[threadInfo.id] = threadInfo;
- return acc;
- },
- {},
- );
-
- // Apply `migrationFunc` to `threadInfo`s.
- const updatedThreadIDToThreadInfo = migrationFunc(threadIDToThreadInfo);
-
- // Convert the updated `threadInfo`s back into an array.
- const updatedRawThreadInfos: $ReadOnlyArray<
- LegacyRawThreadInfo | RawThreadInfo,
- > = values(updatedThreadIDToThreadInfo);
-
- // Translate `RawThreadInfo`s to `ClientDBThreadInfo`s.
- const convertedClientDBThreadInfos: $ReadOnlyArray<ClientDBThreadInfo> =
- updatedRawThreadInfos.map(convertRawThreadInfoToClientDBThreadInfo);
-
- // Construct `ClientDBThreadStoreOperation`s to clear SQLite `threads`
- // table and repopulate with `ClientDBThreadInfo`s.
- return [
- {
- type: 'remove_all',
- },
- ...convertedClientDBThreadInfos.map((thread: ClientDBThreadInfo) => ({
- type: 'replace',
- payload: thread,
- })),
- ];
-}
+import { entries } from 'lib/utils/objects.js';
function createUpdateDBOpsForMessageStoreMessages(
clientDBMessageInfos: $ReadOnlyArray<ClientDBMessageInfo>,
@@ -157,8 +69,6 @@
}
export {
- updateClientDBThreadStoreThreadInfos,
- createUpdateDBOpsForThreadStoreThreadInfos,
createUpdateDBOpsForMessageStoreMessages,
createUpdateDBOpsForMessageStoreThreads,
};
diff --git a/native/redux/deprecated-client-db-utils.js b/native/redux/deprecated-client-db-utils.js
new file mode 100644
--- /dev/null
+++ b/native/redux/deprecated-client-db-utils.js
@@ -0,0 +1 @@
+// @flow
diff --git a/native/redux/client-db-utils.js b/native/redux/deprecated-update-client-db-thread-store-thread-infos.js
copy from native/redux/client-db-utils.js
copy to native/redux/deprecated-update-client-db-thread-store-thread-infos.js
--- a/native/redux/client-db-utils.js
+++ b/native/redux/deprecated-update-client-db-thread-store-thread-infos.js
@@ -1,26 +1,13 @@
// @flow
-import type { ClientDBMessageStoreOperation } from 'lib/ops/message-store-ops.js';
import type { ClientDBThreadStoreOperation } from 'lib/ops/thread-store-ops.js';
-import type {
- RawMessageInfo,
- ClientDBMessageInfo,
- ClientDBThreadMessageInfo,
-} from 'lib/types/message-types.js';
import type { RawThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
import type {
ClientDBThreadInfo,
LegacyRawThreadInfo,
MixedRawThreadInfos,
} from 'lib/types/thread-types.js';
-import {
- translateClientDBMessageInfoToRawMessageInfo,
- translateRawMessageInfoToClientDBMessageInfo,
- translateClientDBThreadMessageInfos,
- translateThreadMessageInfoToClientDBThreadMessageInfo,
- type TranslatedThreadMessageInfos,
-} from 'lib/utils/message-ops-utils.js';
-import { values, entries } from 'lib/utils/objects.js';
+import { values } from 'lib/utils/objects.js';
import {
convertRawThreadInfoToClientDBThreadInfo,
deprecatedConvertClientDBThreadInfoToRawThreadInfo,
@@ -29,7 +16,7 @@
import type { AppState } from './state-types.js';
import { commCoreModule } from '../native-modules.js';
-function updateClientDBThreadStoreThreadInfos(
+function deprecatedUpdateClientDBThreadStoreThreadInfos(
state: AppState,
migrationFunc: MixedRawThreadInfos => MixedRawThreadInfos,
handleMigrationFailure?: AppState => AppState,
@@ -37,7 +24,7 @@
// Get threads from SQLite `threads` table.
const clientDBThreadInfos = commCoreModule.getAllThreadsSync();
- const operations = createUpdateDBOpsForThreadStoreThreadInfos(
+ const operations = deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos(
clientDBThreadInfos,
migrationFunc,
);
@@ -57,7 +44,7 @@
return state;
}
-function createUpdateDBOpsForThreadStoreThreadInfos(
+function deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos(
clientDBThreadInfos: $ReadOnlyArray<ClientDBThreadInfo>,
migrationFunc: MixedRawThreadInfos => MixedRawThreadInfos,
): $ReadOnlyArray<ClientDBThreadStoreOperation> {
@@ -103,62 +90,5 @@
];
}
-function createUpdateDBOpsForMessageStoreMessages(
- clientDBMessageInfos: $ReadOnlyArray<ClientDBMessageInfo>,
- migrationFunc: (
- $ReadOnlyArray<RawMessageInfo>,
- ) => $ReadOnlyArray<RawMessageInfo>,
-): $ReadOnlyArray<ClientDBMessageStoreOperation> {
- const rawMessageInfos = clientDBMessageInfos.map(
- translateClientDBMessageInfoToRawMessageInfo,
- );
-
- const convertedRawMessageInfos = migrationFunc(rawMessageInfos);
-
- const replaceMessagesOperations: $ReadOnlyArray<ClientDBMessageStoreOperation> =
- convertedRawMessageInfos.map(messageInfo => ({
- type: 'replace',
- payload: translateRawMessageInfoToClientDBMessageInfo(messageInfo),
- }));
-
- return [
- {
- type: 'remove_all',
- },
- ...replaceMessagesOperations,
- ];
-}
-
-function createUpdateDBOpsForMessageStoreThreads(
- messageStoreThreads: $ReadOnlyArray<ClientDBThreadMessageInfo>,
- migrationFunc: TranslatedThreadMessageInfos => TranslatedThreadMessageInfos,
-): $ReadOnlyArray<ClientDBMessageStoreOperation> {
- const translatedMessageStoreThreads =
- translateClientDBThreadMessageInfos(messageStoreThreads);
-
- const convertedTranslatedMessageStoreThreads = migrationFunc(
- translatedMessageStoreThreads,
- );
-
- return [
- {
- type: 'remove_all_threads',
- },
- {
- type: 'replace_threads',
- payload: {
- threads: entries(convertedTranslatedMessageStoreThreads).map(
- ([id, thread]) =>
- translateThreadMessageInfoToClientDBThreadMessageInfo(id, thread),
- ),
- },
- },
- ];
-}
-
-export {
- updateClientDBThreadStoreThreadInfos,
- createUpdateDBOpsForThreadStoreThreadInfos,
- createUpdateDBOpsForMessageStoreMessages,
- createUpdateDBOpsForMessageStoreThreads,
-};
+export { deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos };
+export { deprecatedUpdateClientDBThreadStoreThreadInfos };
diff --git a/native/redux/persist.js b/native/redux/persist.js
--- a/native/redux/persist.js
+++ b/native/redux/persist.js
@@ -99,12 +99,14 @@
import { ashoatKeyserverID } from 'lib/utils/validation-utils.js';
import {
- updateClientDBThreadStoreThreadInfos,
- createUpdateDBOpsForThreadStoreThreadInfos,
createUpdateDBOpsForMessageStoreMessages,
createUpdateDBOpsForMessageStoreThreads,
} from './client-db-utils.js';
import { defaultState } from './default-state.js';
+import {
+ deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos,
+ deprecatedUpdateClientDBThreadStoreThreadInfos,
+} from './deprecated-update-client-db-thread-store-thread-infos.js';
import { migrateThreadStoreForEditThreadPermissions } from './edit-thread-permission-migration.js';
import { legacyUpdateRolesAndPermissions } from './legacy-update-roles-and-permissions.js';
import { persistMigrationForManagePinsThreadPermission } from './manage-pins-permission-migration.js';
@@ -636,13 +638,13 @@
return state;
},
[38]: (state: AppState) =>
- updateClientDBThreadStoreThreadInfos(
+ deprecatedUpdateClientDBThreadStoreThreadInfos(
state,
legacyUpdateRolesAndPermissions,
),
[39]: (state: AppState) => unshimClientDB(state, [messageTypes.EDIT_MESSAGE]),
[40]: (state: AppState) =>
- updateClientDBThreadStoreThreadInfos(
+ deprecatedUpdateClientDBThreadStoreThreadInfos(
state,
legacyUpdateRolesAndPermissions,
),
@@ -689,10 +691,11 @@
messageInfos.map(convertRawMessageInfoToNewIDSchema),
);
- const threadOperations = createUpdateDBOpsForThreadStoreThreadInfos(
- threads,
- convertThreadStoreThreadInfosToNewIDSchema,
- );
+ const threadOperations =
+ deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos(
+ threads,
+ convertThreadStoreThreadInfosToNewIDSchema,
+ );
const draftOperations = generateIDSchemaMigrationOpsForDrafts(drafts);
@@ -1020,7 +1023,7 @@
return state;
},
[60]: (state: AppState) =>
- updateClientDBThreadStoreThreadInfos(
+ deprecatedUpdateClientDBThreadStoreThreadInfos(
state,
legacyUpdateRolesAndPermissions,
handleReduxMigrationFailure,
@@ -1044,7 +1047,7 @@
},
{},
);
- return updateClientDBThreadStoreThreadInfos(
+ return deprecatedUpdateClientDBThreadStoreThreadInfos(
state,
minimallyEncodeThreadInfosFunc,
handleReduxMigrationFailure,

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 4:06 PM (3 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2707428
Default Alt Text
D11057.id37042.diff (11 KB)

Event Timeline