Page MenuHomePhorge

D11095.1765203937.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D11095.1765203937.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,11 +1,18 @@
// @flow
+import _keyBy from 'lodash/fp/keyBy.js';
+
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 {
+ ClientDBThreadInfo,
+ RawThreadInfos,
+} from 'lib/types/thread-types.js';
import {
translateClientDBMessageInfoToRawMessageInfo,
translateRawMessageInfoToClientDBMessageInfo,
@@ -13,7 +20,44 @@
translateThreadMessageInfoToClientDBThreadMessageInfo,
type TranslatedThreadMessageInfos,
} from 'lib/utils/message-ops-utils.js';
-import { entries } from 'lib/utils/objects.js';
+import { entries, values } from 'lib/utils/objects.js';
+import {
+ convertClientDBThreadInfoToRawThreadInfo,
+ convertRawThreadInfoToClientDBThreadInfo,
+} from 'lib/utils/thread-ops-utils.js';
+
+function createUpdateDBOpsForThreadStoreThreadInfos(
+ clientDBThreadInfos: $ReadOnlyArray<ClientDBThreadInfo>,
+ migrationFunc: RawThreadInfos => RawThreadInfos,
+): $ReadOnlyArray<ClientDBThreadStoreOperation> {
+ // 1. Translate `ClientDBThreadInfo`s to `RawThreadInfo`s.
+ const rawThreadInfos = clientDBThreadInfos.map(
+ convertClientDBThreadInfoToRawThreadInfo,
+ );
+
+ // 2. Convert `RawThreadInfo`s to a map of `threadID` => `threadInfo`.
+ const keyedRawThreadInfos = _keyBy('id')(rawThreadInfos);
+
+ // 3. Apply `migrationFunc` to `ThreadInfo`s.
+ const updatedKeyedRawThreadInfos = migrationFunc(keyedRawThreadInfos);
+
+ // 4. Convert the updated `RawThreadInfos` back into an array.
+ const updatedKeyedRawThreadInfosArray = values(updatedKeyedRawThreadInfos);
+
+ // 5. Translate `RawThreadInfo`s back to `ClientDBThreadInfo`s.
+ const updatedClientDBThreadInfos = updatedKeyedRawThreadInfosArray.map(
+ convertRawThreadInfoToClientDBThreadInfo,
+ );
+
+ // 6. Construct `replace` `ClientDBThreadStoreOperation`s.
+ const replaceThreadOperations = updatedClientDBThreadInfos.map(thread => ({
+ type: 'replace',
+ payload: thread,
+ }));
+
+ // 7. Prepend `replaceThreadOperations` with `remove_all` op and return.
+ return [{ type: 'remove_all' }, ...replaceThreadOperations];
+}
function createUpdateDBOpsForMessageStoreMessages(
clientDBMessageInfos: $ReadOnlyArray<ClientDBMessageInfo>,
@@ -69,6 +113,7 @@
}
export {
+ createUpdateDBOpsForThreadStoreThreadInfos,
createUpdateDBOpsForMessageStoreMessages,
createUpdateDBOpsForMessageStoreThreads,
};

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 8, 2:25 PM (7 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5848687
Default Alt Text
D11095.1765203937.diff (2 KB)

Event Timeline