diff --git a/keyserver/src/endpoints.js b/keyserver/src/endpoints.js --- a/keyserver/src/endpoints.js +++ b/keyserver/src/endpoints.js @@ -76,6 +76,7 @@ updateUserAvatarResponder, } from './responders/user-responders.js'; import { codeVerificationResponder } from './responders/verification-responders.js'; +import { versionResponder } from './responders/version-responders.js'; import { uploadMediaMetadataResponder, uploadDeletionResponder, @@ -310,6 +311,10 @@ responder: getOlmSessionInitializationDataResponder, requiredPolicies: [], }, + version: { + responder: versionResponder, + requiredPolicies: [], + }, }; export { jsonEndpoints }; diff --git a/keyserver/src/responders/version-responders.js b/keyserver/src/responders/version-responders.js new file mode 100644 --- /dev/null +++ b/keyserver/src/responders/version-responders.js @@ -0,0 +1,25 @@ +// @flow + +import t, { type TInterface } from 'tcomb'; + +import { webAndKeyserverCodeVersion } from 'lib/facts/version.js'; +import type { VersionResponse } from 'lib/types/device-types.js'; +import { tShape } from 'lib/utils/validation-utils.js'; + +import type { Viewer } from '../session/viewer.js'; +import { validateOutput } from '../utils/validation-utils.js'; + +const versionResponseValidator: TInterface = + tShape({ codeVersion: t.Number }); + +const versionResponse = { codeVersion: webAndKeyserverCodeVersion }; + +async function versionResponder(viewer: Viewer): Promise { + return validateOutput( + viewer.platformDetails, + versionResponseValidator, + versionResponse, + ); +} + +export { versionResponder }; 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 @@ -40,3 +40,7 @@ +codeVersion?: number, +stateVersion?: number, }; + +export type VersionResponse = { + +codeVersion: number, +}; diff --git a/lib/types/endpoints.js b/lib/types/endpoints.js --- a/lib/types/endpoints.js +++ b/lib/types/endpoints.js @@ -95,6 +95,7 @@ UPLOAD_MEDIA_METADATA: 'upload_media_metadata', SEARCH_MESSAGES: 'search_messages', GET_OLM_SESSION_INITIALIZATION_DATA: 'get_olm_session_initialization_data', + VERSION: 'version', }); type SocketPreferredEndpoint = $Values;