Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3377603
D10754.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D10754.diff
View Options
diff --git a/lib/shared/transforms/keyserver-store-transform.js b/lib/shared/transforms/keyserver-store-transform.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/transforms/keyserver-store-transform.js
@@ -0,0 +1,83 @@
+// @flow
+
+import { createTransform } from 'redux-persist';
+import type { Transform } from 'redux-persist/es/types.js';
+
+import type {
+ KeyserverInfo,
+ KeyserverStore,
+} from '../../types/keyserver-types.js';
+import {
+ type ConnectionInfo,
+ defaultConnectionInfo,
+} from '../../types/socket-types.js';
+
+export type PersistedKeyserverInfo = $Diff<
+ KeyserverInfo,
+ {
+ +connection: ConnectionInfo,
+ +sessionID?: ?string,
+ },
+>;
+export type PersistedKeyserverStore = {
+ +keyserverInfos: { +[key: string]: PersistedKeyserverInfo },
+};
+
+function transformKeyserverInfoToPersistedKeyserverInfo(
+ keyserverInfo: KeyserverInfo,
+): PersistedKeyserverInfo {
+ const { connection, sessionID, ...rest } = keyserverInfo;
+ return rest;
+}
+
+function transformPersistedKeyserverInfoToKeyserverInfo(
+ persistedKeyserverInfo: PersistedKeyserverInfo,
+): KeyserverInfo {
+ return {
+ ...persistedKeyserverInfo,
+ connection: defaultConnectionInfo,
+ updatesCurrentAsOf: persistedKeyserverInfo.updatesCurrentAsOf ?? 0,
+ };
+}
+
+function transformKeyserverStoreToPersistedKeyserverStore(
+ state: KeyserverStore,
+): PersistedKeyserverStore {
+ const keyserverInfos: { [string]: PersistedKeyserverInfo } = {};
+ for (const key in state.keyserverInfos) {
+ keyserverInfos[key] = transformKeyserverInfoToPersistedKeyserverInfo(
+ state.keyserverInfos[key],
+ );
+ }
+ return {
+ ...state,
+ keyserverInfos,
+ };
+}
+
+function transformPersistedKeyserverStoreToKeyserverStore(
+ state: PersistedKeyserverStore,
+): KeyserverStore {
+ const keyserverInfos: { [string]: KeyserverInfo } = {};
+ for (const key in state.keyserverInfos) {
+ keyserverInfos[key] = transformPersistedKeyserverInfoToKeyserverInfo(
+ state.keyserverInfos[key],
+ );
+ }
+ return {
+ ...state,
+ keyserverInfos,
+ };
+}
+
+const keyserverStoreTransform: Transform = createTransform(
+ transformKeyserverStoreToPersistedKeyserverStore,
+ transformPersistedKeyserverStoreToKeyserverStore,
+ { whitelist: ['keyserverStore'] },
+);
+
+export {
+ transformKeyserverInfoToPersistedKeyserverInfo,
+ transformPersistedKeyserverInfoToKeyserverInfo,
+ keyserverStoreTransform,
+};
diff --git a/native/redux/persist.js b/native/redux/persist.js
--- a/native/redux/persist.js
+++ b/native/redux/persist.js
@@ -41,6 +41,7 @@
getCommunity,
assertAllThreadInfosAreLegacy,
} from 'lib/shared/thread-utils.js';
+import { keyserverStoreTransform } from 'lib/shared/transforms/keyserver-store-transform.js';
import {
DEPRECATED_unshimMessageStore,
unshimFunc,
@@ -48,10 +49,7 @@
import { defaultEnabledApps } from 'lib/types/enabled-apps.js';
import { defaultCalendarQuery } from 'lib/types/entry-types.js';
import { defaultCalendarFilters } from 'lib/types/filter-types.js';
-import type {
- KeyserverStore,
- KeyserverInfo,
-} from 'lib/types/keyserver-types.js';
+import type { KeyserverInfo } from 'lib/types/keyserver-types.js';
import {
messageTypes,
type MessageType,
@@ -68,10 +66,7 @@
ReportStore,
ClientReportCreationRequest,
} from 'lib/types/report-types.js';
-import {
- defaultConnectionInfo,
- type ConnectionInfo,
-} from 'lib/types/socket-types.js';
+import { defaultConnectionInfo } from 'lib/types/socket-types.js';
import { defaultGlobalThemeInfo } from 'lib/types/theme-types.js';
import type {
ClientDBThreadInfo,
@@ -1078,41 +1073,6 @@
{ whitelist: ['reportStore'] },
);
-type PersistedKeyserverInfo = $Diff<
- KeyserverInfo,
- { +connection: ConnectionInfo },
->;
-type PersistedKeyserverStore = {
- +keyserverInfos: { +[key: string]: PersistedKeyserverInfo },
-};
-const keyserverStoreTransform: Transform = createTransform(
- (state: KeyserverStore): PersistedKeyserverStore => {
- const keyserverInfos: { [string]: PersistedKeyserverInfo } = {};
- for (const key in state.keyserverInfos) {
- const { connection, ...rest } = state.keyserverInfos[key];
- keyserverInfos[key] = rest;
- }
- return {
- ...state,
- keyserverInfos,
- };
- },
- (state: PersistedKeyserverStore): KeyserverStore => {
- const keyserverInfos: { [string]: KeyserverInfo } = {};
- for (const key in state.keyserverInfos) {
- keyserverInfos[key] = {
- ...state.keyserverInfos[key],
- connection: { ...defaultConnectionInfo },
- };
- }
- return {
- ...state,
- keyserverInfos,
- };
- },
- { whitelist: ['keyserverStore'] },
-);
-
const persistConfig = {
key: 'root',
storage: AsyncStorage,
diff --git a/web/redux/persist.js b/web/redux/persist.js
--- a/web/redux/persist.js
+++ b/web/redux/persist.js
@@ -1,28 +1,18 @@
// @flow
import invariant from 'invariant';
-import {
- getStoredState,
- purgeStoredState,
- createTransform,
-} from 'redux-persist';
+import { getStoredState, purgeStoredState } from 'redux-persist';
import storage from 'redux-persist/es/storage/index.js';
-import type { Transform } from 'redux-persist/es/types.js';
import type { PersistConfig } from 'redux-persist/src/types.js';
import {
createAsyncMigrate,
type StorageMigrationFunction,
} from 'lib/shared/create-async-migrate.js';
-import type {
- KeyserverInfo,
- KeyserverStore,
-} from 'lib/types/keyserver-types.js';
+import { keyserverStoreTransform } from 'lib/shared/transforms/keyserver-store-transform.js';
+import type { KeyserverInfo } from 'lib/types/keyserver-types.js';
import { cookieTypes } from 'lib/types/session-types.js';
-import {
- defaultConnectionInfo,
- type ConnectionInfo,
-} from 'lib/types/socket-types.js';
+import { defaultConnectionInfo } from 'lib/types/socket-types.js';
import { defaultGlobalThemeInfo } from 'lib/types/theme-types.js';
import { parseCookies } from 'lib/utils/cookie-utils.js';
import { isDev } from 'lib/utils/dev-utils.js';
@@ -247,46 +237,6 @@
return newStorage;
};
-type PersistedKeyserverInfo = $Diff<
- KeyserverInfo,
- {
- +connection: ConnectionInfo,
- +sessionID?: ?string,
- },
->;
-type PersistedKeyserverStore = {
- +keyserverInfos: { +[key: string]: PersistedKeyserverInfo },
-};
-const keyserverStoreTransform: Transform = createTransform(
- (state: KeyserverStore): PersistedKeyserverStore => {
- const keyserverInfos: { [string]: PersistedKeyserverInfo } = {};
- for (const key in state.keyserverInfos) {
- const { connection, sessionID, ...rest } = state.keyserverInfos[key];
- keyserverInfos[key] = rest;
- }
- return {
- ...state,
- keyserverInfos,
- };
- },
- (state: PersistedKeyserverStore): KeyserverStore => {
- const keyserverInfos: { [string]: KeyserverInfo } = {};
- for (const key in state.keyserverInfos) {
- keyserverInfos[key] = {
- ...state.keyserverInfos[key],
- connection: { ...defaultConnectionInfo },
- sessionID: null,
- updatesCurrentAsOf: state.keyserverInfos[key].updatesCurrentAsOf ?? 0,
- };
- }
- return {
- ...state,
- keyserverInfos,
- };
- },
- { whitelist: ['keyserverStore'] },
-);
-
const persistConfig: PersistConfig = {
key: rootKey,
storage: commReduxStorageEngine,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 6:35 AM (21 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2593085
Default Alt Text
D10754.diff (7 KB)
Attached To
Mode
D10754: [native][web][lib] unify keyserver transform
Attached
Detach File
Event Timeline
Log In to Comment