diff --git a/lib/types/keyserver-types.js b/lib/types/keyserver-types.js --- a/lib/types/keyserver-types.js +++ b/lib/types/keyserver-types.js @@ -3,8 +3,11 @@ import t, { type TInterface } from 'tcomb'; import type { PlatformDetails } from './device-types.js'; -import { connectionInfoValidator } from './socket-types.js'; -import type { ConnectionInfo } from './socket-types.js'; +import { + type ConnectionInfo, + connectionInfoValidator, + defaultConnectionInfo, +} from './socket-types.js'; import type { GlobalAccountUserInfo } from './user-types.js'; import { tShape, tPlatformDetails } from '../utils/validation-utils.js'; @@ -18,6 +21,17 @@ +deviceToken: ?string, }; +const defaultKeyserverInfo: ( + urlPrefix: string, +) => KeyserverInfo = urlPrefix => ({ + cookie: null, + updatesCurrentAsOf: 0, + urlPrefix, + connection: defaultConnectionInfo, + lastCommunicatedPlatformDetails: null, + deviceToken: null, +}); + export type KeyserverInfos = { +[key: string]: KeyserverInfo }; export type KeyserverStore = { @@ -53,3 +67,5 @@ tShape({ keyserverInfos: t.dict(t.String, keyserverInfoValidator), }); + +export { defaultKeyserverInfo }; diff --git a/native/profile/add-keyserver.react.js b/native/profile/add-keyserver.react.js --- a/native/profile/add-keyserver.react.js +++ b/native/profile/add-keyserver.react.js @@ -7,7 +7,7 @@ import { addKeyserverActionType } from 'lib/actions/keyserver-actions.js'; import { useIsKeyserverURLValid } from 'lib/shared/keyserver-utils.js'; import type { KeyserverInfo } from 'lib/types/keyserver-types.js'; -import { defaultConnectionInfo } from 'lib/types/socket-types.js'; +import { defaultKeyserverInfo } from 'lib/types/keyserver-types.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; import type { ProfileNavigationProp } from './profile.react.js'; @@ -55,14 +55,7 @@ return; } - const newKeyserverInfo: KeyserverInfo = { - cookie: null, - updatesCurrentAsOf: 0, - urlPrefix: urlInput, - connection: defaultConnectionInfo, - lastCommunicatedPlatformDetails: null, - deviceToken: null, - }; + const newKeyserverInfo: KeyserverInfo = defaultKeyserverInfo(urlInput); dispatch({ type: addKeyserverActionType, diff --git a/native/redux/default-state.js b/native/redux/default-state.js --- a/native/redux/default-state.js +++ b/native/redux/default-state.js @@ -6,7 +6,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 { defaultConnectionInfo } from 'lib/types/socket-types.js'; +import { defaultKeyserverInfo } from 'lib/types/keyserver-types.js'; import { defaultGlobalThemeInfo } from 'lib/types/theme-types.js'; import { defaultNotifPermissionAlertInfo } from 'lib/utils/push-alerts.js'; import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; @@ -72,14 +72,7 @@ }, keyserverStore: { keyserverInfos: { - [ashoatKeyserverID]: { - cookie: null, - updatesCurrentAsOf: 0, - urlPrefix: defaultURLPrefix, - connection: defaultConnectionInfo, - lastCommunicatedPlatformDetails: null, - deviceToken: null, - }, + [ashoatKeyserverID]: defaultKeyserverInfo(defaultURLPrefix), }, }, localSettings: { diff --git a/web/modals/keyserver-selection/add-keyserver-modal.react.js b/web/modals/keyserver-selection/add-keyserver-modal.react.js --- a/web/modals/keyserver-selection/add-keyserver-modal.react.js +++ b/web/modals/keyserver-selection/add-keyserver-modal.react.js @@ -6,7 +6,7 @@ import { useModalContext } from 'lib/components/modal-provider.react.js'; import { useIsKeyserverURLValid } from 'lib/shared/keyserver-utils.js'; import type { KeyserverInfo } from 'lib/types/keyserver-types.js'; -import { defaultConnectionInfo } from 'lib/types/socket-types.js'; +import { defaultKeyserverInfo } from 'lib/types/keyserver-types.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; import css from './add-keyserver-modal.css'; @@ -52,14 +52,7 @@ return; } - const newKeyserverInfo: KeyserverInfo = { - cookie: null, - updatesCurrentAsOf: 0, - urlPrefix: keyserverURL, - connection: defaultConnectionInfo, - lastCommunicatedPlatformDetails: null, - deviceToken: null, - }; + const newKeyserverInfo: KeyserverInfo = defaultKeyserverInfo(keyserverURL); dispatch({ type: addKeyserverActionType, diff --git a/web/redux/default-state.js b/web/redux/default-state.js --- a/web/redux/default-state.js +++ b/web/redux/default-state.js @@ -2,7 +2,7 @@ import { defaultWebEnabledApps } from 'lib/types/enabled-apps.js'; import { defaultCalendarFilters } from 'lib/types/filter-types.js'; -import { defaultConnectionInfo } from 'lib/types/socket-types.js'; +import { defaultKeyserverInfo } from 'lib/types/keyserver-types.js'; import { defaultGlobalThemeInfo } from 'lib/types/theme-types.js'; import { defaultNotifPermissionAlertInfo } from 'lib/utils/push-alerts.js'; import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; @@ -71,14 +71,7 @@ communityPickerStore: { chat: null, calendar: null }, keyserverStore: { keyserverInfos: { - [ashoatKeyserverID]: { - cookie: null, - updatesCurrentAsOf: 0, - urlPrefix: keyserverURL, - connection: { ...defaultConnectionInfo }, - lastCommunicatedPlatformDetails: null, - deviceToken: null, - }, + [ashoatKeyserverID]: defaultKeyserverInfo(keyserverURL), }, }, threadActivityStore: {},