Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3185562
D11057.id37272.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D11057.id37272.diff
View Options
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,18 +1,11 @@
// @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,
@@ -20,88 +13,7 @@
translateThreadMessageInfoToClientDBThreadMessageInfo,
type TranslatedThreadMessageInfos,
} 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/client-db-utils.js b/native/redux/deprecated-client-db-utils.js
copy from native/redux/client-db-utils.js
copy to native/redux/deprecated-client-db-utils.js
--- a/native/redux/client-db-utils.js
+++ b/native/redux/deprecated-client-db-utils.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,7 @@
];
}
-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,
+ deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos,
+ 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-client-db-utils.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
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 9, 1:01 PM (18 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2452507
Default Alt Text
D11057.id37272.diff (10 KB)
Attached To
Mode
D11057: [native] Deprecate and move `updateClientDBThreadStoreThreadInfos` and `createUpdateDBOpsForThreadStoreThreadInfos`
Attached
Detach File
Event Timeline
Log In to Comment