Page MenuHomePhabricator

D8619.diff
No OneTemporary

D8619.diff

diff --git a/lib/ops/thread-store-ops.js b/lib/ops/thread-store-ops.js
--- a/lib/ops/thread-store-ops.js
+++ b/lib/ops/thread-store-ops.js
@@ -1,9 +1,15 @@
// @flow
+import { type BaseStoreOpsHandlers } from './base-ops.js';
import type {
ClientDBThreadInfo,
RawThreadInfo,
+ ThreadStore,
} from '../types/thread-types.js';
+import {
+ convertClientDBThreadInfoToRawThreadInfo,
+ convertRawThreadInfoToClientDBThreadInfo,
+} from '../utils/thread-ops-utils.js';
export type RemoveThreadOperation = {
+type: 'remove',
@@ -33,3 +39,60 @@
| RemoveThreadOperation
| RemoveAllThreadsOperation
| ClientDBReplaceThreadOperation;
+
+export const threadStoreOpsHandlers: BaseStoreOpsHandlers<
+ ThreadStore,
+ ThreadStoreOperation,
+ ClientDBThreadStoreOperation,
+ { +[id: string]: RawThreadInfo },
+ ClientDBThreadInfo,
+> = {
+ processStoreOperations(
+ store: ThreadStore,
+ ops: $ReadOnlyArray<ThreadStoreOperation>,
+ ): ThreadStore {
+ if (ops.length === 0) {
+ return store;
+ }
+ let processedThreads = { ...store.threadInfos };
+ for (const operation of ops) {
+ if (operation.type === 'replace') {
+ processedThreads[operation.payload.id] = operation.payload.threadInfo;
+ } else if (operation.type === 'remove') {
+ for (const id of operation.payload.ids) {
+ delete processedThreads[id];
+ }
+ } else if (operation.type === 'remove_all') {
+ processedThreads = {};
+ }
+ }
+ return { ...store, threadInfos: processedThreads };
+ },
+
+ convertOpsToClientDBOps(
+ ops: $ReadOnlyArray<ThreadStoreOperation>,
+ ): $ReadOnlyArray<ClientDBThreadStoreOperation> {
+ return ops.map(threadStoreOperation => {
+ if (threadStoreOperation.type === 'replace') {
+ return {
+ type: 'replace',
+ payload: convertRawThreadInfoToClientDBThreadInfo(
+ threadStoreOperation.payload.threadInfo,
+ ),
+ };
+ }
+ return threadStoreOperation;
+ });
+ },
+
+ translateClientDBData(data: $ReadOnlyArray<ClientDBThreadInfo>): {
+ +[id: string]: RawThreadInfo,
+ } {
+ return Object.fromEntries(
+ data.map((dbThreadInfo: ClientDBThreadInfo) => [
+ dbThreadInfo.id,
+ convertClientDBThreadInfoToRawThreadInfo(dbThreadInfo),
+ ]),
+ );
+ },
+};
diff --git a/lib/reducers/thread-reducer.js b/lib/reducers/thread-reducer.js
--- a/lib/reducers/thread-reducer.js
+++ b/lib/reducers/thread-reducer.js
@@ -25,7 +25,10 @@
registerActionTypes,
updateSubscriptionActionTypes,
} from '../actions/user-actions.js';
-import type { ThreadStoreOperation } from '../ops/thread-store-ops.js';
+import {
+ type ThreadStoreOperation,
+ threadStoreOpsHandlers,
+} from '../ops/thread-store-ops.js';
import type { BaseAction } from '../types/redux-types.js';
import {
type ClientThreadInconsistencyReportCreationRequest,
@@ -51,6 +54,9 @@
import { generateReportID } from '../utils/report-utils.js';
import { sanitizeActionSecrets } from '../utils/sanitization.js';
+const { processStoreOperations: processThreadStoreOperations } =
+ threadStoreOpsHandlers;
+
function generateOpsForThreadUpdates(
threadInfos: { +[id: string]: RawThreadInfo },
payload: {
@@ -484,26 +490,4 @@
};
}
-function processThreadStoreOperations(
- threadStore: ThreadStore,
- threadStoreOperations: $ReadOnlyArray<ThreadStoreOperation>,
-): ThreadStore {
- if (threadStoreOperations.length === 0) {
- return threadStore;
- }
- let processedThreads = { ...threadStore.threadInfos };
- for (const operation of threadStoreOperations) {
- if (operation.type === 'replace') {
- processedThreads[operation.payload.id] = operation.payload.threadInfo;
- } else if (operation.type === 'remove') {
- for (const id of operation.payload.ids) {
- delete processedThreads[id];
- }
- } else if (operation.type === 'remove_all') {
- processedThreads = {};
- }
- }
- return { ...threadStore, threadInfos: processedThreads };
-}
-
-export { reduceThreadInfos, processThreadStoreOperations };
+export { reduceThreadInfos };
diff --git a/lib/utils/thread-ops-utils.js b/lib/utils/thread-ops-utils.js
--- a/lib/utils/thread-ops-utils.js
+++ b/lib/utils/thread-ops-utils.js
@@ -1,9 +1,5 @@
// @flow
-import type {
- ClientDBThreadStoreOperation,
- ThreadStoreOperation,
-} from '../ops/thread-store-ops.js';
import { assertThreadType } from '../types/thread-types-enum.js';
import {
type ClientDBThreadInfo,
@@ -60,36 +56,7 @@
return rawThreadInfo;
}
-function convertThreadStoreOperationsToClientDBOperations(
- threadStoreOperations: $ReadOnlyArray<ThreadStoreOperation>,
-): $ReadOnlyArray<ClientDBThreadStoreOperation> {
- return threadStoreOperations.map(threadStoreOperation => {
- if (threadStoreOperation.type === 'replace') {
- return {
- type: 'replace',
- payload: convertRawThreadInfoToClientDBThreadInfo(
- threadStoreOperation.payload.threadInfo,
- ),
- };
- }
- return threadStoreOperation;
- });
-}
-
-function convertClientDBThreadInfosToRawThreadInfos(
- clientDBThreadInfos: $ReadOnlyArray<ClientDBThreadInfo>,
-): { +[id: string]: RawThreadInfo } {
- return Object.fromEntries(
- clientDBThreadInfos.map((dbThreadInfo: ClientDBThreadInfo) => [
- dbThreadInfo.id,
- convertClientDBThreadInfoToRawThreadInfo(dbThreadInfo),
- ]),
- );
-}
-
export {
convertRawThreadInfoToClientDBThreadInfo,
convertClientDBThreadInfoToRawThreadInfo,
- convertThreadStoreOperationsToClientDBOperations,
- convertClientDBThreadInfosToRawThreadInfos,
};
diff --git a/native/data/sqlite-data-handler.js b/native/data/sqlite-data-handler.js
--- a/native/data/sqlite-data-handler.js
+++ b/native/data/sqlite-data-handler.js
@@ -7,6 +7,7 @@
import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions.js';
import { MediaCacheContext } from 'lib/components/media-cache-provider.react.js';
import { convertClientDBReportToClientReportCreationRequest } from 'lib/ops/report-store-ops.js';
+import { threadStoreOpsHandlers } from 'lib/ops/thread-store-ops.js';
import { cookieSelector } from 'lib/selectors/keyserver-selectors.js';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
import {
@@ -15,7 +16,6 @@
} from 'lib/types/account-types.js';
import { fetchNewCookieFromNativeCredentials } from 'lib/utils/action-utils.js';
import { getMessageForException } from 'lib/utils/errors.js';
-import { convertClientDBThreadInfosToRawThreadInfos } from 'lib/utils/thread-ops-utils.js';
import { filesystemMediaCache } from '../media/media-cache.js';
import { commCoreModule } from '../native-modules.js';
@@ -172,7 +172,7 @@
const { threads, messages, drafts, messageStoreThreads, reports } =
await commCoreModule.getClientDBStore();
const threadInfosFromDB =
- convertClientDBThreadInfosToRawThreadInfos(threads);
+ threadStoreOpsHandlers.translateClientDBData(threads);
const reportsFromDb =
convertClientDBReportToClientReportCreationRequest(reports);
diff --git a/native/redux/persist.js b/native/redux/persist.js
--- a/native/redux/persist.js
+++ b/native/redux/persist.js
@@ -23,6 +23,7 @@
convertReportsToReplaceReportOps,
} from 'lib/ops/report-store-ops.js';
import type { ClientDBThreadStoreOperation } from 'lib/ops/thread-store-ops.js';
+import { threadStoreOpsHandlers } from 'lib/ops/thread-store-ops.js';
import { highestLocalIDSelector } from 'lib/selectors/local-id-selectors.js';
import { createAsyncMigrate } from 'lib/shared/create-async-migrate.js';
import { inconsistencyResponsesToReports } from 'lib/shared/report-utils.js';
@@ -61,7 +62,6 @@
import {
convertClientDBThreadInfoToRawThreadInfo,
convertRawThreadInfoToClientDBThreadInfo,
- convertThreadStoreOperationsToClientDBOperations,
} from 'lib/utils/thread-ops-utils.js';
import { getUUID } from 'lib/utils/uuid.js';
import { ashoatKeyserverID } from 'lib/utils/validation-utils.js';
@@ -398,7 +398,7 @@
];
try {
commCoreModule.processThreadStoreOperationsSync(
- convertThreadStoreOperationsToClientDBOperations(operations),
+ threadStoreOpsHandlers.convertOpsToClientDBOps(operations),
);
} catch (exception) {
console.log(exception);
diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js
--- a/native/redux/redux-setup.js
+++ b/native/redux/redux-setup.js
@@ -14,8 +14,8 @@
logInActionTypes,
} from 'lib/actions/user-actions.js';
import type { ThreadStoreOperation } from 'lib/ops/thread-store-ops.js';
+import { threadStoreOpsHandlers } from 'lib/ops/thread-store-ops.js';
import baseReducer from 'lib/reducers/master-reducer.js';
-import { processThreadStoreOperations } from 'lib/reducers/thread-reducer.js';
import {
invalidSessionDowngrade,
invalidSessionRecovery,
@@ -430,7 +430,7 @@
},
];
- const updatedThreadStore = processThreadStoreOperations(
+ const updatedThreadStore = threadStoreOpsHandlers.processStoreOperations(
state.threadStore,
threadStoreOperations,
);
diff --git a/native/redux/redux-utils.js b/native/redux/redux-utils.js
--- a/native/redux/redux-utils.js
+++ b/native/redux/redux-utils.js
@@ -3,9 +3,9 @@
import { useSelector as reactReduxUseSelector } from 'react-redux';
import { convertReportStoreOperationToClientDBReportStoreOperation } from 'lib/ops/report-store-ops.js';
+import { threadStoreOpsHandlers } from 'lib/ops/thread-store-ops.js';
import type { StoreOperations } from 'lib/types/store-ops-types.js';
import { convertMessageStoreOperationsToClientDBOperations } from 'lib/utils/message-ops-utils.js';
-import { convertThreadStoreOperationsToClientDBOperations } from 'lib/utils/thread-ops-utils.js';
import type { AppState } from './state-types.js';
import { commCoreModule } from '../native-modules.js';
@@ -29,7 +29,7 @@
} = storeOperations;
const convertedThreadStoreOperations =
- convertThreadStoreOperationsToClientDBOperations(threadStoreOperations);
+ threadStoreOpsHandlers.convertOpsToClientDBOps(threadStoreOperations);
const convertedMessageStoreOperations =
convertMessageStoreOperationsToClientDBOperations(messageStoreOperations);
const convertedReportStoreOperations =

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 29, 5:44 PM (22 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2597670
Default Alt Text
D8619.diff (10 KB)

Event Timeline