Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3393042
D9636.id32507.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D9636.id32507.diff
View Options
diff --git a/keyserver/src/responders/version-responders.js b/keyserver/src/responders/version-responders.js
--- a/keyserver/src/responders/version-responders.js
+++ b/keyserver/src/responders/version-responders.js
@@ -4,15 +4,32 @@
import { webAndKeyserverCodeVersion } from 'lib/facts/version.js';
import type { VersionResponse } from 'lib/types/device-types.js';
+import { getCommConfig } from 'lib/utils/comm-config.js';
import { tShape } from 'lib/utils/validation-utils.js';
-export const versionResponseValidator: TInterface<VersionResponse> =
- tShape<VersionResponse>({ codeVersion: t.Number });
+import type { UserCredentials } from '../user/checks.js';
+import { fetchIdentityInfo } from '../user/identity.js';
-const versionResponse = { codeVersion: webAndKeyserverCodeVersion };
+export const versionResponseValidator: TInterface<VersionResponse> =
+ tShape<VersionResponse>({
+ codeVersion: t.Number,
+ ownerUsername: t.maybe(t.String),
+ ownerID: t.maybe(t.String),
+ });
async function versionResponder(): Promise<VersionResponse> {
- return versionResponse;
+ const userInfo = await getCommConfig<UserCredentials>({
+ folder: 'secrets',
+ name: 'user_credentials',
+ });
+
+ const identityInfo = await fetchIdentityInfo();
+
+ return {
+ codeVersion: webAndKeyserverCodeVersion,
+ ownerUsername: userInfo?.username,
+ ownerID: identityInfo?.userId,
+ };
}
export { versionResponder };
diff --git a/keyserver/src/user/checks.js b/keyserver/src/user/checks.js
--- a/keyserver/src/user/checks.js
+++ b/keyserver/src/user/checks.js
@@ -1,7 +1,7 @@
// @flow
import { getCommConfig } from 'lib/utils/comm-config.js';
-type UserCredentials = { +username: string, +password: string };
+export type UserCredentials = { +username: string, +password: string };
async function ensureUserCredentials() {
const userCredentials = await getCommConfig<UserCredentials>({
diff --git a/lib/actions/device-actions.js b/lib/actions/device-actions.js
--- a/lib/actions/device-actions.js
+++ b/lib/actions/device-actions.js
@@ -1,7 +1,6 @@
// @flow
import type { VersionResponse } from '../types/device-types.js';
-import type { CallServerEndpoint } from '../utils/call-server-endpoint.js';
import { getConfig } from '../utils/config.js';
import type { CallKeyserverEndpoint } from '../utils/keyserver-call.js';
@@ -49,17 +48,30 @@
return result;
};
+const TEMPORARY_KS_ID = 'TEMPORARY';
+// We don't know the keyserver's id yet, so to use the CallKeyserverEndpoint
+// we use a temporary keyserver id.
+// To use this, pass paramOverride to useKeyserverCall,
+// containing in the keyserverInfos an entry for TEMPORARY_KS_ID
+const getVersionRequests = {
+ [TEMPORARY_KS_ID]: {},
+};
+
const getVersionActionTypes = Object.freeze({
started: 'GET_VERSION_STARTED',
success: 'GET_VERSION_SUCCESS',
failed: 'GET_VERSION_FAILED',
});
const getVersion =
- (callServerEndpoint: CallServerEndpoint): (() => Promise<VersionResponse>) =>
+ (
+ callKeyserverEndpoint: CallKeyserverEndpoint,
+ ): (() => Promise<VersionResponse>) =>
async () => {
- const response = await callServerEndpoint('version');
+ const response = await callKeyserverEndpoint('version', getVersionRequests);
return {
- codeVersion: response.codeVersion,
+ codeVersion: response[TEMPORARY_KS_ID].codeVersion,
+ ownerUsername: response[TEMPORARY_KS_ID].ownerUsername,
+ ownerID: response[TEMPORARY_KS_ID].ownerID,
};
};
@@ -70,6 +82,7 @@
setDeviceTokenActionTypes,
setDeviceToken,
setDeviceTokenFanout,
+ TEMPORARY_KS_ID,
getVersionActionTypes,
getVersion,
updateLastCommunicatedPlatformDetailsActionType,
diff --git a/lib/types/device-types.js b/lib/types/device-types.js
--- a/lib/types/device-types.js
+++ b/lib/types/device-types.js
@@ -43,4 +43,6 @@
export type VersionResponse = {
+codeVersion: number,
+ +ownerUsername: ?string,
+ +ownerID: ?string,
};
diff --git a/lib/utils/keyserver-call.js b/lib/utils/keyserver-call.js
--- a/lib/utils/keyserver-call.js
+++ b/lib/utils/keyserver-call.js
@@ -73,10 +73,12 @@
const createBoundServerCallsSelector: CreateBoundServerCallsSelectorType =
(_memoize(baseCreateBoundServerCallsSelector): any);
+export type KeyserverInfoPartial = $Shape<KeyserverInfo>;
+
export type BindKeyserverCallParams = {
+dispatch: Dispatch,
+currentUserInfo: ?CurrentUserInfo,
- +keyserverInfos: { +[keyserverID: string]: KeyserverInfo },
+ +keyserverInfos: { +[keyserverID: string]: KeyserverInfoPartial },
};
const bindCallKeyserverEndpointSelector = createSelector(
@@ -114,7 +116,7 @@
cookie,
urlPrefix,
sessionID,
- connectionStatus: connection.status,
+ connectionStatus: connection?.status,
lastCommunicatedPlatformDetails,
});
diff --git a/native/account/registration/keyserver-selection.react.js b/native/account/registration/keyserver-selection.react.js
--- a/native/account/registration/keyserver-selection.react.js
+++ b/native/account/registration/keyserver-selection.react.js
@@ -5,14 +5,13 @@
import { Text, View } from 'react-native';
import {
+ TEMPORARY_KS_ID,
getVersion,
getVersionActionTypes,
} from 'lib/actions/device-actions.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
-import {
- useServerCall,
- useDispatchActionPromise,
-} from 'lib/utils/action-utils.js';
+import { useDispatchActionPromise } from 'lib/utils/action-utils.js';
+import { useKeyserverCall } from 'lib/utils/keyserver-call.js';
import RegistrationButtonContainer from './registration-button-container.react.js';
import RegistrationButton from './registration-button.react.js';
@@ -112,11 +111,15 @@
const serverCallParamOverride = React.useMemo(
() => ({
- urlPrefix: keyserverURL,
+ keyserverInfos: {
+ [TEMPORARY_KS_ID]: {
+ urlPrefix: keyserverURL,
+ },
+ },
}),
[keyserverURL],
);
- const getVersionCall = useServerCall(getVersion, serverCallParamOverride);
+ const getVersionCall = useKeyserverCall(getVersion, serverCallParamOverride);
const dispatchActionPromise = useDispatchActionPromise();
const { navigate } = props.navigation;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 1, 11:10 AM (18 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2604859
Default Alt Text
D9636.id32507.diff (6 KB)
Attached To
Mode
D9636: [keyserver][lib][native] Refactor getVersion action
Attached
Detach File
Event Timeline
Log In to Comment