diff --git a/lib/actions/link-actions.js b/lib/actions/link-actions.js --- a/lib/actions/link-actions.js +++ b/lib/actions/link-actions.js @@ -10,7 +10,7 @@ DisableInviteLinkRequest, DisableInviteLinkPayload, } from '../types/link-types.js'; -import type { CallServerEndpoint } from '../utils/call-server-endpoint.js'; +import type { CallSingleKeyserverEndpoint } from '../utils/call-single-keyserver-endpoint.js'; import { useKeyserverCall } from '../utils/keyserver-call.js'; import type { CallKeyserverEndpoint } from '../utils/keyserver-call.js'; @@ -21,12 +21,15 @@ }); const verifyInviteLink = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): (( request: InviteLinkVerificationRequest, ) => Promise) => async request => { - const response = await callServerEndpoint('verify_invite_link', request); + const response = await callSingleKeyserverEndpoint( + 'verify_invite_link', + request, + ); if (response.status === 'valid' || response.status === 'already_joined') { return { status: response.status, diff --git a/lib/actions/message-actions.js b/lib/actions/message-actions.js --- a/lib/actions/message-actions.js +++ b/lib/actions/message-actions.js @@ -26,7 +26,7 @@ ToggleMessagePinRequest, ToggleMessagePinResult, } from '../types/thread-types.js'; -import type { CallServerEndpointResultInfo } from '../utils/call-server-endpoint.js'; +import type { CallSingleKeyserverEndpointResultInfo } from '../utils/call-single-keyserver-endpoint.js'; import { useKeyserverCall } from '../utils/keyserver-call.js'; import type { CallKeyserverEndpoint } from '../utils/keyserver-call.js'; @@ -178,7 +178,9 @@ ): ((input: SendTextMessageInput) => Promise) => async input => { let resultInfo; - const getResultInfo = (passedResultInfo: CallServerEndpointResultInfo) => { + const getResultInfo = ( + passedResultInfo: CallSingleKeyserverEndpointResultInfo, + ) => { resultInfo = passedResultInfo; }; const { threadID, localID, text, sidebarCreation } = input; @@ -235,7 +237,9 @@ ): ((input: SendMultimediaMessageInput) => Promise) => async input => { let resultInfo; - const getResultInfo = (passedResultInfo: CallServerEndpointResultInfo) => { + const getResultInfo = ( + passedResultInfo: CallSingleKeyserverEndpointResultInfo, + ) => { resultInfo = passedResultInfo; }; const { threadID, localID, mediaMessageContents, sidebarCreation } = input; @@ -285,7 +289,9 @@ ) => Promise) => async input => { let resultInfo; - const getResultInfo = (passedResultInfo: CallServerEndpointResultInfo) => { + const getResultInfo = ( + passedResultInfo: CallSingleKeyserverEndpointResultInfo, + ) => { resultInfo = passedResultInfo; }; const { threadID, localID, mediaIDs, sidebarCreation } = input; @@ -331,7 +337,9 @@ ): ((input: SendReactionMessageRequest) => Promise) => async input => { let resultInfo; - const getResultInfo = (passedResultInfo: CallServerEndpointResultInfo) => { + const getResultInfo = ( + passedResultInfo: CallSingleKeyserverEndpointResultInfo, + ) => { resultInfo = passedResultInfo; }; diff --git a/lib/actions/relationship-actions.js b/lib/actions/relationship-actions.js --- a/lib/actions/relationship-actions.js +++ b/lib/actions/relationship-actions.js @@ -4,7 +4,7 @@ RelationshipRequest, RelationshipErrors, } from '../types/relationship-types.js'; -import type { CallServerEndpoint } from '../utils/call-server-endpoint.js'; +import type { CallSingleKeyserverEndpoint } from '../utils/call-single-keyserver-endpoint.js'; import { ServerError } from '../utils/errors.js'; const updateRelationshipsActionTypes = Object.freeze({ @@ -14,10 +14,13 @@ }); const updateRelationships = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): ((request: RelationshipRequest) => Promise) => async request => { - const errors = await callServerEndpoint('update_relationships', request); + const errors = await callSingleKeyserverEndpoint( + 'update_relationships', + request, + ); const { invalid_user, already_friends, user_blocked } = errors; if (invalid_user) { diff --git a/lib/actions/siwe-actions.js b/lib/actions/siwe-actions.js --- a/lib/actions/siwe-actions.js +++ b/lib/actions/siwe-actions.js @@ -8,9 +8,9 @@ } from '../types/account-types.js'; import type { SIWEAuthServerCall } from '../types/siwe-types.js'; import type { - CallServerEndpoint, - CallServerEndpointOptions, -} from '../utils/call-server-endpoint.js'; + CallSingleKeyserverEndpoint, + CallSingleKeyserverEndpointOptions, +} from '../utils/call-single-keyserver-endpoint.js'; import { getConfig } from '../utils/config.js'; import { ashoatKeyserverID } from '../utils/validation-utils.js'; @@ -20,9 +20,11 @@ failed: 'GET_SIWE_NONCE_FAILED', }); const getSIWENonce = - (callServerEndpoint: CallServerEndpoint): (() => Promise) => + ( + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, + ): (() => Promise) => async () => { - const response = await callServerEndpoint('siwe_nonce'); + const response = await callSingleKeyserverEndpoint('siwe_nonce'); return response.nonce; }; @@ -31,20 +33,20 @@ success: 'SIWE_AUTH_SUCCESS', failed: 'SIWE_AUTH_FAILED', }); -const siweAuthCallServerEndpointOptions = { timeout: 60000 }; +const siweAuthCallSingleKeyserverEndpointOptions = { timeout: 60000 }; const siweAuth = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): (( siweAuthPayload: SIWEAuthServerCall, - options?: ?CallServerEndpointOptions, + options?: ?CallSingleKeyserverEndpointOptions, ) => Promise) => async (siweAuthPayload, options) => { const watchedIDs = threadWatcher.getWatchedIDs(); const deviceTokenUpdateRequest = siweAuthPayload.deviceTokenUpdateRequest[ashoatKeyserverID]; - const response = await callServerEndpoint( + const response = await callSingleKeyserverEndpoint( 'siwe_auth', { ...siweAuthPayload, @@ -53,7 +55,7 @@ platformDetails: getConfig().platformDetails, }, { - ...siweAuthCallServerEndpointOptions, + ...siweAuthCallSingleKeyserverEndpointOptions, ...options, }, ); diff --git a/lib/actions/upload-actions.js b/lib/actions/upload-actions.js --- a/lib/actions/upload-actions.js +++ b/lib/actions/upload-actions.js @@ -11,7 +11,7 @@ type BlobServiceUploadHandler, } from '../utils/blob-service-upload.js'; import { makeBlobServiceEndpointURL } from '../utils/blob-service.js'; -import type { CallServerEndpoint } from '../utils/call-server-endpoint.js'; +import type { CallSingleKeyserverEndpoint } from '../utils/call-single-keyserver-endpoint.js'; import { getMessageForException } from '../utils/errors.js'; import { useKeyserverCall } from '../utils/keyserver-call.js'; import type { CallKeyserverEndpoint } from '../utils/keyserver-call.js'; @@ -36,7 +36,7 @@ const uploadMultimedia = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): (( multimedia: Object, extras: MultimediaUploadExtras, @@ -69,7 +69,7 @@ stringExtras.mimeType = multimedia.type; } - const response = await callServerEndpoint( + const response = await callSingleKeyserverEndpoint( 'upload_multimedia', { ...stringExtras, diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -59,9 +59,9 @@ LoggedOutUserInfo, } from '../types/user-types.js'; import type { - CallServerEndpoint, - CallServerEndpointOptions, -} from '../utils/call-server-endpoint.js'; + CallSingleKeyserverEndpoint, + CallSingleKeyserverEndpointOptions, +} from '../utils/call-single-keyserver-endpoint.js'; import { getConfig } from '../utils/config.js'; import type { CallKeyserverEndpoint } from '../utils/keyserver-call'; import { useKeyserverCall } from '../utils/keyserver-call.js'; @@ -128,7 +128,7 @@ success: 'CLAIM_USERNAME_SUCCESS', failed: 'CLAIM_USERNAME_FAILED', }); -const claimUsernameCallServerEndpointOptions = { timeout: 500 }; +const claimUsernameCallSingleKeyserverEndpointOptions = { timeout: 500 }; const claimUsername = ( callKeyserverEndpoint: CallKeyserverEndpoint, @@ -136,7 +136,7 @@ async () => { const requests = { [ashoatKeyserverID]: {} }; const responses = await callKeyserverEndpoint('claim_username', requests, { - ...claimUsernameCallServerEndpointOptions, + ...claimUsernameCallSingleKeyserverEndpointOptions, }); const response = responses[ashoatKeyserverID]; return { @@ -210,19 +210,19 @@ success: 'KEYSERVER_REGISTER_SUCCESS', failed: 'KEYSERVER_REGISTER_FAILED', }); -const registerCallServerEndpointOptions = { timeout: 60000 }; +const registerCallSingleKeyserverEndpointOptions = { timeout: 60000 }; const keyserverRegister = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): (( registerInfo: RegisterInfo, - options?: CallServerEndpointOptions, + options?: CallSingleKeyserverEndpointOptions, ) => Promise) => async (registerInfo, options) => { const deviceTokenUpdateRequest = registerInfo.deviceTokenUpdateRequest[ashoatKeyserverID]; - const response = await callServerEndpoint( + const response = await callSingleKeyserverEndpoint( 'create_account', { ...registerInfo, @@ -230,7 +230,7 @@ platformDetails: getConfig().platformDetails, }, { - ...registerCallServerEndpointOptions, + ...registerCallSingleKeyserverEndpointOptions, ...options, }, ); @@ -253,7 +253,7 @@ success: 'KEYSERVER_AUTH_SUCCESS', failed: 'KEYSERVER_AUTH_FAILED', }); -const keyserverAuthCallServerEndpointOptions = { timeout: 60000 }; +const keyserverAuthCallSingleKeyserverEndpointOptions = { timeout: 60000 }; const keyserverAuth = ( callKeyserverEndpoint: CallKeyserverEndpoint, @@ -298,7 +298,7 @@ await callKeyserverEndpoint( 'keyserver_auth', requests, - keyserverAuthCallServerEndpointOptions, + keyserverAuthCallSingleKeyserverEndpointOptions, ); const userInfosArrays = []; @@ -436,7 +436,7 @@ success: 'LOG_IN_SUCCESS', failed: 'LOG_IN_FAILED', }); -const logInCallServerEndpointOptions = { timeout: 60000 }; +const logInCallSingleKeyserverEndpointOptions = { timeout: 60000 }; const logIn = ( callKeyserverEndpoint: CallKeyserverEndpoint, @@ -477,7 +477,7 @@ await callKeyserverEndpoint( 'log_in', requests, - logInCallServerEndpointOptions, + logInCallSingleKeyserverEndpointOptions, ); const userInfosArrays = []; @@ -549,10 +549,10 @@ }); const changeKeyserverUserPassword = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): ((passwordUpdate: PasswordUpdate) => Promise) => async passwordUpdate => { - await callServerEndpoint('update_account', passwordUpdate); + await callSingleKeyserverEndpoint('update_account', passwordUpdate); }; const searchUsersActionTypes = Object.freeze({ @@ -562,10 +562,10 @@ }); const searchUsers = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): ((usernamePrefix: string) => Promise) => async usernamePrefix => { - const response = await callServerEndpoint('search_users', { + const response = await callSingleKeyserverEndpoint('search_users', { prefix: usernamePrefix, }); return { @@ -580,10 +580,10 @@ }); const exactSearchUser = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): ((username: string) => Promise) => async username => { - const response = await callServerEndpoint('exact_search_user', { + const response = await callSingleKeyserverEndpoint('exact_search_user', { username, }); return { @@ -650,10 +650,10 @@ const getSessionPublicKeys = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): ((data: GetSessionPublicKeysArgs) => Promise) => async data => { - return await callServerEndpoint('get_session_public_keys', data); + return await callSingleKeyserverEndpoint('get_session_public_keys', data); }; const getOlmSessionInitializationDataActionTypes = Object.freeze({ @@ -664,12 +664,12 @@ const getOlmSessionInitializationData = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): (( - options?: ?CallServerEndpointOptions, + options?: ?CallSingleKeyserverEndpointOptions, ) => Promise) => async options => { - return await callServerEndpoint( + return await callSingleKeyserverEndpoint( 'get_olm_session_initialization_data', {}, options, @@ -683,10 +683,10 @@ }); const policyAcknowledgment = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): ((policyRequest: PolicyAcknowledgmentRequest) => Promise) => async policyRequest => { - await callServerEndpoint('policy_acknowledgment', policyRequest); + await callSingleKeyserverEndpoint('policy_acknowledgment', policyRequest); }; const updateUserAvatarActionTypes = Object.freeze({ @@ -696,15 +696,13 @@ }); const updateUserAvatar = ( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, ): (( avatarDBContent: UpdateUserAvatarRequest, ) => Promise) => async avatarDBContent => { - const { updates }: UpdateUserAvatarResponse = await callServerEndpoint( - 'update_user_avatar', - avatarDBContent, - ); + const { updates }: UpdateUserAvatarResponse = + await callSingleKeyserverEndpoint('update_user_avatar', avatarDBContent); return { updates }; }; diff --git a/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js b/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js --- a/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js +++ b/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js @@ -16,14 +16,14 @@ import type { ClientSessionChange } from '../types/session-types.js'; import type { CurrentUserInfo } from '../types/user-types.js'; import type { - CallServerEndpoint, - CallServerEndpointOptions, -} from '../utils/call-server-endpoint.js'; -import callServerEndpoint from '../utils/call-server-endpoint.js'; + CallSingleKeyserverEndpoint, + CallSingleKeyserverEndpointOptions, +} from '../utils/call-single-keyserver-endpoint.js'; +import callSingleKeyserverEndpoint from '../utils/call-single-keyserver-endpoint.js'; type CreateCallSingleKeyserverEndpointSelector = ( keyserverID: string, -) => ServerCallSelectorParams => CallServerEndpoint; +) => ServerCallSelectorParams => CallSingleKeyserverEndpoint; type CallKeyserverEndpointContextType = { +createCallSingleKeyserverEndpointSelector: CreateCallSingleKeyserverEndpointSelector, }; @@ -32,7 +32,9 @@ React.createContext(); type OngoingRecoveryAttempt = { - +waitingCalls: Array<(callServerEndpoint: ?CallServerEndpoint) => mixed>, + +waitingCalls: Array< + (callSingleKeyserverEndpoint: ?CallSingleKeyserverEndpoint) => mixed, + >, }; export type ServerCallSelectorParams = { @@ -57,9 +59,9 @@ Map, >(new Map()); - const bindCookieAndUtilsIntoCallServerEndpoint: ( + const bindCookieAndUtilsIntoCallSingleKeyserverEndpoint: ( params: BindServerCallsParams, - ) => CallServerEndpoint = React.useCallback(params => { + ) => CallSingleKeyserverEndpoint = React.useCallback(params => { const { dispatch, cookie, @@ -87,13 +89,13 @@ keyserverID, ); const canResolveInvalidation = canResolveKeyserverSessionInvalidation(); - // This function gets called before callServerEndpoint sends a request, - // to make sure that we're not in the middle of trying to recover + // This function gets called before callSingleKeyserverEndpoint sends a + // request, to make sure that we're not in the middle of trying to recover // an invalidated cookie const waitIfCookieInvalidated = () => { if (!canResolveInvalidation) { // If there is no way to resolve the session invalidation, - // just let the caller callServerEndpoint instance continue + // just let the caller callSingleKeyserverEndpoint instance continue return Promise.resolve(null); } const ongoingRecoveryAttempt = @@ -103,7 +105,7 @@ return Promise.resolve(null); } // Wait to run until we get our new cookie - return new Promise(r => + return new Promise(r => ongoingRecoveryAttempt.waitingCalls.push(r), ); }; @@ -125,8 +127,8 @@ ongoingRecoveryAttemptsRef.current.delete(keyserverID); const currentWaitingCalls = ongoingRecoveryAttempt?.waitingCalls ?? []; - const newCallServerEndpoint = newSessionChange - ? bindCookieAndUtilsIntoCallServerEndpoint({ + const newCallSingleKeyserverEndpoint = newSessionChange + ? bindCookieAndUtilsIntoCallSingleKeyserverEndpoint({ ...params, cookie: newSessionChange.cookie, sessionID: newSessionChange.sessionID, @@ -134,17 +136,17 @@ }) : null; for (const func of currentWaitingCalls) { - func(newCallServerEndpoint); + func(newCallSingleKeyserverEndpoint); } - return newCallServerEndpoint; + return newCallSingleKeyserverEndpoint; }; - // If this function is called, callServerEndpoint got a response + // If this function is called, callSingleKeyserverEndpoint got a response // invalidating its cookie, and is wondering if it should just like... // give up? Or if there's a chance at redemption const cookieInvalidationRecovery = (sessionChange: ClientSessionChange) => { if (!canResolveInvalidation) { // If there is no way to resolve the session invalidation, - // just let the caller callServerEndpoint instance continue + // just let the caller callSingleKeyserverEndpoint instance continue return Promise.resolve(null); } if (!loggedIn) { @@ -155,7 +157,7 @@ const ongoingRecoveryAttempt = ongoingRecoveryAttemptsRef.current.get(keyserverID); if (ongoingRecoveryAttempt) { - return new Promise(r => + return new Promise(r => ongoingRecoveryAttempt.waitingCalls.push(r), ); } @@ -166,9 +168,9 @@ return ( endpoint: Endpoint, data: Object, - options?: ?CallServerEndpointOptions, + options?: ?CallSingleKeyserverEndpointOptions, ) => - callServerEndpoint( + callSingleKeyserverEndpoint( cookie, boundSetNewSession, waitIfCookieInvalidated, @@ -188,12 +190,15 @@ }, []); // For each keyserver, we have a set of params that configure our connection - // to it. These params get bound into callServerEndpoint before it's passed to - // an ActionFunc. This helper function lets us create a selector for a given - // keyserverID that will regenerate the bound callServerEndpoint function only - // if one of the params changes. This lets us skip some React render cycles. + // to it. These params get bound into callSingleKeyserverEndpoint before it's + // passed to an ActionFunc. This helper function lets us create a selector for + // a given keyserverID that will regenerate the bound + // callSingleKeyserverEndpoint function only if one of the params changes. + // This lets us skip some React render cycles. const createCallSingleKeyserverEndpointSelector = React.useCallback( - (keyserverID: string): (ServerCallSelectorParams => CallServerEndpoint) => + ( + keyserverID: string, + ): (ServerCallSelectorParams => CallSingleKeyserverEndpoint) => createSelector( (params: ServerCallSelectorParams) => params.dispatch, (params: ServerCallSelectorParams) => params.cookie, @@ -212,7 +217,7 @@ isSocketConnected: boolean, lastCommunicatedPlatformDetails: ?PlatformDetails, ) => - bindCookieAndUtilsIntoCallServerEndpoint({ + bindCookieAndUtilsIntoCallSingleKeyserverEndpoint({ dispatch, cookie, urlPrefix, @@ -223,7 +228,7 @@ keyserverID, }), ), - [bindCookieAndUtilsIntoCallServerEndpoint], + [bindCookieAndUtilsIntoCallSingleKeyserverEndpoint], ); const value = React.useMemo( diff --git a/lib/keyserver-conn/recovery-utils.js b/lib/keyserver-conn/recovery-utils.js --- a/lib/keyserver-conn/recovery-utils.js +++ b/lib/keyserver-conn/recovery-utils.js @@ -9,8 +9,8 @@ import type { Endpoint } from '../types/endpoints.js'; import type { Dispatch } from '../types/redux-types.js'; import type { ClientSessionChange } from '../types/session-types.js'; -import callServerEndpoint from '../utils/call-server-endpoint.js'; -import type { CallServerEndpointOptions } from '../utils/call-server-endpoint.js'; +import callSingleKeyServerEndpoint from '../utils/call-single-keyserver-endpoint.js'; +import type { CallSingleKeyserverEndpointOptions } from '../utils/call-single-keyserver-endpoint.js'; import { getConfig } from '../utils/config.js'; import { promiseAll } from '../utils/promises.js'; import { wrapActionPromise } from '../utils/redux-promise-utils.js'; @@ -53,11 +53,11 @@ return null; } let newSessionChange = null; - let callServerEndpointCallback = null; - const boundCallServerEndpoint = async ( + let callSingleKeyserverEndpointCallback = null; + const boundCallSingleKeyserverEndpoint = async ( endpoint: Endpoint, data: { +[key: string]: mixed }, - options?: ?CallServerEndpointOptions, + options?: ?CallSingleKeyserverEndpointOptions, ) => { const innerBoundSetNewSession = ( sessionChange: ClientSessionChange, @@ -74,7 +74,7 @@ ); }; try { - const result = await callServerEndpoint( + const result = await callSingleKeyServerEndpoint( cookie, innerBoundSetNewSession, () => new Promise(r => r(null)), @@ -91,13 +91,13 @@ false, keyserverID, ); - if (callServerEndpointCallback) { - callServerEndpointCallback(!!newSessionChange); + if (callSingleKeyserverEndpointCallback) { + callSingleKeyserverEndpointCallback(!!newSessionChange); } return result; } catch (e) { - if (callServerEndpointCallback) { - callServerEndpointCallback(!!newSessionChange); + if (callSingleKeyserverEndpointCallback) { + callSingleKeyserverEndpointCallback(!!newSessionChange); } throw e; } @@ -106,11 +106,11 @@ const boundCallKeyserverEndpoint = ( endpoint: Endpoint, requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, - options?: ?CallServerEndpointOptions, + options?: ?CallSingleKeyserverEndpointOptions, ) => { if (requests[keyserverID]) { const promises = { - [keyserverID]: boundCallServerEndpoint( + [keyserverID]: boundCallSingleKeyserverEndpoint( endpoint, requests[keyserverID], options, @@ -134,10 +134,10 @@ void dispatch( wrapActionPromise(actionTypes, promise, null, startingPayload), ); - return new Promise(r => (callServerEndpointCallback = r)); + return new Promise(r => (callSingleKeyserverEndpointCallback = r)); }; await resolveKeyserverSessionInvalidationUsingNativeCredentials( - boundCallServerEndpoint, + boundCallSingleKeyserverEndpoint, boundCallKeyserverEndpoint, dispatchRecoveryAttempt, logInActionSource, diff --git a/lib/shared/crypto-utils.js b/lib/shared/crypto-utils.js --- a/lib/shared/crypto-utils.js +++ b/lib/shared/crypto-utils.js @@ -1,4 +1,4 @@ -//@flow +// @flow import * as React from 'react'; @@ -14,15 +14,15 @@ import type { OlmSessionInitializationInfo } from '../types/request-types'; import { useServerCall } from '../utils/action-utils.js'; import type { - CallServerEndpointOptions, - CallServerEndpoint, -} from '../utils/call-server-endpoint.js'; + CallSingleKeyserverEndpointOptions, + CallSingleKeyserverEndpoint, +} from '../utils/call-single-keyserver-endpoint.js'; import { values, entries } from '../utils/objects.js'; import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; export type InitialNotifMessageOptions = { - +callServerEndpoint?: ?CallServerEndpoint, - +callServerEndpointOptions?: ?CallServerEndpointOptions, + +callSingleKeyserverEndpoint?: ?CallSingleKeyserverEndpoint, + +callSingleKeyserverEndpointOptions?: ?CallSingleKeyserverEndpointOptions, }; const initialEncryptedMessageContent = { @@ -42,13 +42,16 @@ return React.useCallback( async options => { - const callServerEndpoint = options?.callServerEndpoint; - const callServerEndpointOptions = options?.callServerEndpointOptions; + const callSingleKeyserverEndpoint = options?.callSingleKeyserverEndpoint; + const callSingleKeyserverEndpointOptions = + options?.callSingleKeyserverEndpointOptions; - const initDataAction = callServerEndpoint - ? getOlmSessionInitializationData(callServerEndpoint) + const initDataAction = callSingleKeyserverEndpoint + ? getOlmSessionInitializationData(callSingleKeyserverEndpoint) : callGetOlmSessionInitializationData; - const olmSessionDataPromise = initDataAction(callServerEndpointOptions); + const olmSessionDataPromise = initDataAction( + callSingleKeyserverEndpointOptions, + ); void dispatchActionPromise( getOlmSessionInitializationDataActionTypes, diff --git a/lib/shared/timeouts.js b/lib/shared/timeouts.js --- a/lib/shared/timeouts.js +++ b/lib/shared/timeouts.js @@ -17,10 +17,10 @@ // unlikely, as the connectivity issue is likely on the client side. export const clientRequestSocketTimeout = 10000; // in milliseconds -// Time after which CallServerEndpoint will timeout a request. When using -// sockets this is preempted by the above timeout, so it really only applies -// for HTTP requests. -export const callServerEndpointTimeout = 10000; // in milliseconds +// Time after which CallSingleKeyserverEndpoint will timeout a request. When +// using sockets this is preempted by the above timeout, so it really only +// applies for HTTP requests. +export const callSingleKeyserverEndpointTimeout = 10000; // in milliseconds // The server expects to get a request at least every three // seconds from the client. If server doesn't get a request diff --git a/lib/types/message-types.js b/lib/types/message-types.js --- a/lib/types/message-types.js +++ b/lib/types/message-types.js @@ -137,7 +137,7 @@ type UpdateRelationshipMessageInfo, } from './messages/update-relationship.js'; import { type RelativeUserInfo, type UserInfos } from './user-types.js'; -import type { CallServerEndpointResultInfoInterface } from '../utils/call-server-endpoint.js'; +import type { CallSingleKeyserverEndpointResultInfoInterface } from '../utils/call-single-keyserver-endpoint.js'; import { values } from '../utils/objects.js'; import { tID, tNumber, tShape } from '../utils/validation-utils.js'; @@ -583,7 +583,7 @@ export type SendMessageResult = { +id: string, +time: number, - +interface: CallServerEndpointResultInfoInterface, + +interface: CallSingleKeyserverEndpointResultInfoInterface, }; export type SendMessagePayload = { @@ -591,7 +591,7 @@ +serverID: string, +threadID: string, +time: number, - +interface: CallServerEndpointResultInfoInterface, + +interface: CallSingleKeyserverEndpointResultInfoInterface, }; export type SendTextMessageRequest = { diff --git a/lib/utils/action-utils.js b/lib/utils/action-utils.js --- a/lib/utils/action-utils.js +++ b/lib/utils/action-utils.js @@ -3,7 +3,7 @@ import invariant from 'invariant'; import * as React from 'react'; -import type { CallServerEndpoint } from './call-server-endpoint.js'; +import type { CallSingleKeyserverEndpoint } from './call-single-keyserver-endpoint.js'; import { useSelector, useDispatch } from './redux-utils.js'; import { ashoatKeyserverID } from './validation-utils.js'; import { @@ -12,7 +12,9 @@ } from '../keyserver-conn/call-keyserver-endpoint-provider.react.js'; import { serverCallStateSelector } from '../selectors/server-calls.js'; -type ActionFunc = (callServerEndpoint: CallServerEndpoint) => F; +type ActionFunc = ( + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, +) => F; function useServerCall( serverCall: ActionFunc, @@ -38,14 +40,14 @@ 'keyserver missing from keyserverStore', ); - const callServerEndpoint = selector({ + const callSingleKeyserverEndpoint = selector({ ...serverCallState, urlPrefix, isSocketConnected, dispatch, ...paramOverride, }); - return serverCall(callServerEndpoint); + return serverCall(callSingleKeyserverEndpoint); }, [serverCall, serverCallState, dispatch, paramOverride, selector]); } diff --git a/lib/utils/call-server-endpoint.js b/lib/utils/call-single-keyserver-endpoint.js rename from lib/utils/call-server-endpoint.js rename to lib/utils/call-single-keyserver-endpoint.js --- a/lib/utils/call-server-endpoint.js +++ b/lib/utils/call-single-keyserver-endpoint.js @@ -12,7 +12,7 @@ import sleep from './sleep.js'; import { uploadBlob, type UploadBlob } from './upload-blob.js'; import { updateLastCommunicatedPlatformDetailsActionType } from '../actions/device-actions.js'; -import { callServerEndpointTimeout } from '../shared/timeouts.js'; +import { callSingleKeyserverEndpointTimeout } from '../shared/timeouts.js'; import type { PlatformDetails } from '../types/device-types.js'; import { type Endpoint, @@ -28,12 +28,12 @@ } from '../types/session-types.js'; import type { CurrentUserInfo } from '../types/user-types.js'; -export type CallServerEndpointOptions = Partial<{ +export type CallSingleKeyserverEndpointOptions = Partial<{ // null timeout means no timeout, which is the default for uploadBlob +timeout: ?number, // in milliseconds - // getResultInfo will be called right before callServerEndpoint successfully - // resolves and includes additional information about the request - +getResultInfo: (resultInfo: CallServerEndpointResultInfo) => mixed, + // getResultInfo will be called right before callSingleKeyserverEndpoint + // successfully resolves and includes additional information about the request + +getResultInfo: (resultInfo: CallSingleKeyserverEndpointResultInfo) => mixed, +blobUpload: boolean | UploadBlob, // the rest (onProgress, abortHandler) only work with blobUpload +onProgress: (percent: number) => void, @@ -43,27 +43,27 @@ +urlPrefixOverride: string, }>; -export type CallServerEndpointResultInfoInterface = 'socket' | 'REST'; -export type CallServerEndpointResultInfo = { - +interface: CallServerEndpointResultInfoInterface, +export type CallSingleKeyserverEndpointResultInfoInterface = 'socket' | 'REST'; +export type CallSingleKeyserverEndpointResultInfo = { + +interface: CallSingleKeyserverEndpointResultInfoInterface, }; -export type CallServerEndpointResponse = Partial<{ +export type CallSingleKeyserverEndpointResponse = Partial<{ +cookieChange: ServerSessionChange, +currentUserInfo: CurrentUserInfo, +error: string, +payload: Object, }>; -// You'll notice that this is not the type of the callServerEndpoint +// You'll notice that this is not the type of the callSingleKeyserverEndpoint // function below. This is because the first several parameters to that // function get bound in by the helpers in lib/utils/action-utils.js. -// This type represents the form of the callServerEndpoint function that -// gets passed to the action function in lib/actions. -export type CallServerEndpoint = ( +// This type represents the form of the callSingleKeyserverEndpoint function +// that gets passed to the action function in lib/actions. +export type CallSingleKeyserverEndpoint = ( endpoint: Endpoint, input: Object, - options?: ?CallServerEndpointOptions, + options?: ?CallSingleKeyserverEndpointOptions, ) => Promise; type RequestData = { @@ -73,13 +73,13 @@ platformDetails?: PlatformDetails, }; -async function callServerEndpoint( +async function callSingleKeyserverEndpoint( cookie: ?string, setNewSession: (sessionChange: ClientSessionChange, error: ?string) => void, - waitIfCookieInvalidated: () => Promise, + waitIfCookieInvalidated: () => Promise, cookieInvalidationRecovery: ( sessionChange: ClientSessionChange, - ) => Promise, + ) => Promise, urlPrefix: string, sessionID: ?string, isSocketConnected: boolean, @@ -88,7 +88,7 @@ endpoint: Endpoint, input: { +[key: string]: mixed }, dispatch: Dispatch, - options?: ?CallServerEndpointOptions, + options?: ?CallSingleKeyserverEndpointOptions, loggedIn: boolean, keyserverID: string, ): Promise { @@ -153,7 +153,7 @@ mergedData.platformDetails = getConfig().platformDetails; } const callEndpointPromise = - (async (): Promise => { + (async (): Promise => { const response = await fetch(url, { method: 'POST', // This is necessary to allow cookie headers to get passed down to us @@ -174,14 +174,16 @@ })(); const timeout = - options && options.timeout ? options.timeout : callServerEndpointTimeout; + options && options.timeout + ? options.timeout + : callSingleKeyserverEndpointTimeout; if (!timeout) { json = await callEndpointPromise; } else { const rejectPromise = (async () => { await sleep(timeout); throw new FetchTimeout( - `callServerEndpoint timed out call to ${endpoint}`, + `callSingleKeyserverEndpoint timed out call to ${endpoint}`, endpoint, ); })(); @@ -226,4 +228,4 @@ return json; } -export default callServerEndpoint; +export default callSingleKeyserverEndpoint; diff --git a/lib/utils/config.js b/lib/utils/config.js --- a/lib/utils/config.js +++ b/lib/utils/config.js @@ -2,7 +2,7 @@ import invariant from 'invariant'; -import type { CallServerEndpoint } from './call-server-endpoint.js'; +import type { CallSingleKeyserverEndpoint } from './call-single-keyserver-endpoint.js'; import type { CallKeyserverEndpoint } from './keyserver-call.js'; import type { DispatchRecoveryAttempt } from '../keyserver-conn/keyserver-conn-types.js'; import type { LogInActionSource } from '../types/account-types.js'; @@ -10,7 +10,7 @@ export type Config = { +resolveKeyserverSessionInvalidationUsingNativeCredentials: ?( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, callKeyserverEndpoint: CallKeyserverEndpoint, dispatchRecoveryAttempt: DispatchRecoveryAttempt, logInActionSource: LogInActionSource, 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 @@ -3,7 +3,7 @@ import _memoize from 'lodash/memoize.js'; import * as React from 'react'; -import type { CallServerEndpointOptions } from './call-server-endpoint.js'; +import type { CallSingleKeyserverEndpointOptions } from './call-single-keyserver-endpoint.js'; import { promiseAll } from './promises.js'; import { useSelector, useDispatch } from './redux-utils.js'; import { useCallKeyserverEndpointContext } from '../keyserver-conn/call-keyserver-endpoint-provider.react.js'; @@ -18,11 +18,11 @@ export type CallKeyserverEndpoint = ( endpoint: Endpoint, requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, - options?: ?CallServerEndpointOptions, + options?: ?CallSingleKeyserverEndpointOptions, ) => Promise<{ +[keyserverID: string]: any }>; type ActionFunc = ( - callServerEndpoint: CallKeyserverEndpoint, + callSingleKeyserverEndpoint: CallKeyserverEndpoint, // The second argument is only used in actions that call all keyservers, // and the request to all keyservers are exactly the same. // An example of such action is fetchEntries. @@ -71,7 +71,7 @@ const callKeyserverEndpoint = ( endpoint: Endpoint, requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, - options?: ?CallServerEndpointOptions, + options?: ?CallSingleKeyserverEndpointOptions, ) => { const makeCallToSingleKeyserver = (keyserverID: string) => { const { @@ -82,19 +82,18 @@ lastCommunicatedPlatformDetails, } = keyserverCallInfos[keyserverID]; - const boundCallServerEndpoint = getCallSingleKeyserverEndpointSelector( - keyserverID, - )({ - dispatch, - currentUserInfo, - cookie, - urlPrefix, - sessionID, - isSocketConnected, - lastCommunicatedPlatformDetails, - }); + const boundCallSingleKeyserverEndpoint = + getCallSingleKeyserverEndpointSelector(keyserverID)({ + dispatch, + currentUserInfo, + cookie, + urlPrefix, + sessionID, + isSocketConnected, + lastCommunicatedPlatformDetails, + }); - return boundCallServerEndpoint( + return boundCallSingleKeyserverEndpoint( endpoint, requests[keyserverID], options, diff --git a/lib/utils/upload-blob.js b/lib/utils/upload-blob.js --- a/lib/utils/upload-blob.js +++ b/lib/utils/upload-blob.js @@ -4,9 +4,9 @@ import _throttle from 'lodash/throttle.js'; import type { - CallServerEndpointOptions, - CallServerEndpointResponse, -} from './call-server-endpoint.js'; + CallSingleKeyserverEndpointOptions, + CallSingleKeyserverEndpointResponse, +} from './call-single-keyserver-endpoint.js'; import { getConfig } from './config.js'; function uploadBlob( @@ -14,8 +14,8 @@ cookie: ?string, sessionID: ?string, input: { +[key: string]: mixed }, - options?: ?CallServerEndpointOptions, -): Promise { + options?: ?CallSingleKeyserverEndpointOptions, +): Promise { const formData = new FormData(); formData.append('cookie', cookie ? cookie : ''); @@ -66,7 +66,7 @@ } let failed = false; - const responsePromise = new Promise( + const responsePromise = new Promise( (resolve, reject) => { xhr.onload = () => { if (failed) { diff --git a/native/account/resolve-invalidated-cookie.js b/native/account/resolve-invalidated-cookie.js --- a/native/account/resolve-invalidated-cookie.js +++ b/native/account/resolve-invalidated-cookie.js @@ -4,7 +4,7 @@ import type { DispatchRecoveryAttempt } from 'lib/keyserver-conn/keyserver-conn-types.js'; import type { InitialNotifMessageOptions } from 'lib/shared/crypto-utils.js'; import type { LogInActionSource } from 'lib/types/account-types.js'; -import type { CallServerEndpoint } from 'lib/utils/call-server-endpoint.js'; +import type { CallSingleKeyserverEndpoint } from 'lib/utils/call-single-keyserver-endpoint.js'; import type { CallKeyserverEndpoint } from 'lib/utils/keyserver-call.js'; import { fetchNativeKeychainCredentials } from './native-credentials.js'; @@ -12,7 +12,7 @@ import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js'; async function resolveKeyserverSessionInvalidationUsingNativeCredentials( - callServerEndpoint: CallServerEndpoint, + callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, callKeyserverEndpoint: CallKeyserverEndpoint, dispatchRecoveryAttempt: DispatchRecoveryAttempt, logInActionSource: LogInActionSource, @@ -29,7 +29,9 @@ if (getInitialNotificationsEncryptedMessage) { const initialNotificationsEncryptedMessage = - await getInitialNotificationsEncryptedMessage({ callServerEndpoint }); + await getInitialNotificationsEncryptedMessage({ + callSingleKeyserverEndpoint, + }); extraInfo = { ...extraInfo, initialNotificationsEncryptedMessage }; } diff --git a/native/account/siwe-hooks.js b/native/account/siwe-hooks.js --- a/native/account/siwe-hooks.js +++ b/native/account/siwe-hooks.js @@ -9,7 +9,7 @@ LogInExtraInfo, } from 'lib/types/account-types.js'; import { useServerCall } from 'lib/utils/action-utils.js'; -import type { CallServerEndpointOptions } from 'lib/utils/call-server-endpoint.js'; +import type { CallSingleKeyserverEndpointOptions } from 'lib/utils/call-single-keyserver-endpoint.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; import { useSelector } from '../redux/redux-utils.js'; @@ -24,7 +24,7 @@ }; function useSIWEServerCall(): ( SIWEServerCallParams, - ?CallServerEndpointOptions, + ?CallSingleKeyserverEndpointOptions, ) => Promise { const siweAuthCall = useServerCall(siweAuth); @@ -33,7 +33,7 @@ message: string, signature: string, extraInfo: $ReadOnly<{ ...LogInExtraInfo, +doNotRegister?: boolean }>, - callServerEndpointOptions: ?CallServerEndpointOptions, + callSingleKeyserverEndpointOptions: ?CallSingleKeyserverEndpointOptions, ) => siweAuthCall( { @@ -41,7 +41,7 @@ signature, ...extraInfo, }, - callServerEndpointOptions, + callSingleKeyserverEndpointOptions, ), [siweAuthCall], ); @@ -55,12 +55,12 @@ return React.useCallback( async ( { message, signature, doNotRegister }, - callServerEndpointOptions, + callSingleKeyserverEndpointOptions, ) => { const extraInfo = await logInExtraInfo(); const initialNotificationsEncryptedMessage = await getInitialNotificationsEncryptedMessage({ - callServerEndpointOptions, + callSingleKeyserverEndpointOptions, }); const siwePromise = callSIWE( @@ -71,7 +71,7 @@ initialNotificationsEncryptedMessage, doNotRegister, }, - callServerEndpointOptions, + callSingleKeyserverEndpointOptions, ); void dispatchActionPromise( diff --git a/native/input/input-state-container.react.js b/native/input/input-state-container.react.js --- a/native/input/input-state-container.react.js +++ b/native/input/input-state-container.react.js @@ -85,9 +85,9 @@ } from 'lib/types/thread-types.js'; import { useServerCall } from 'lib/utils/action-utils.js'; import type { - CallServerEndpointOptions, - CallServerEndpointResponse, -} from 'lib/utils/call-server-endpoint.js'; + CallSingleKeyserverEndpointOptions, + CallSingleKeyserverEndpointResponse, +} from 'lib/utils/call-single-keyserver-endpoint.js'; import { getConfig } from 'lib/utils/config.js'; import { getMessageForException, cloneError } from 'lib/utils/errors.js'; import { values } from 'lib/utils/objects.js'; @@ -1180,8 +1180,8 @@ cookie: ?string, sessionID: ?string, input: { +[key: string]: mixed }, - options?: ?CallServerEndpointOptions, - ): Promise => { + options?: ?CallSingleKeyserverEndpointOptions, + ): Promise => { invariant( cookie && input.multimedia && diff --git a/web/chat/reaction-message-utils.js b/web/chat/reaction-message-utils.js --- a/web/chat/reaction-message-utils.js +++ b/web/chat/reaction-message-utils.js @@ -11,7 +11,7 @@ import type { ReactionInfo } from 'lib/selectors/chat-selectors'; import { messageTypes } from 'lib/types/message-types-enum.js'; import type { RawReactionMessageInfo } from 'lib/types/messages/reaction.js'; -import type { CallServerEndpointResultInfoInterface } from 'lib/utils/call-server-endpoint.js'; +import type { CallSingleKeyserverEndpointResultInfoInterface } from 'lib/utils/call-single-keyserver-endpoint.js'; import { cloneError } from 'lib/utils/errors.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; @@ -62,7 +62,7 @@ }); const serverID: string = result.id; const time: number = result.time; - const interfaceInfo: CallServerEndpointResultInfoInterface = + const interfaceInfo: CallSingleKeyserverEndpointResultInfoInterface = result.interface; return { localID, diff --git a/web/redux/action-types.js b/web/redux/action-types.js --- a/web/redux/action-types.js +++ b/web/redux/action-types.js @@ -20,7 +20,9 @@ export const updateWindowActiveActionType = 'UPDATE_WINDOW_ACTIVE'; export const setInitialReduxState = 'SET_INITIAL_REDUX_STATE'; -const getInitialReduxStateCallServerEndpointOptions = { timeout: 300000 }; +const getInitialReduxStateCallSingleKeyserverEndpointOptions = { + timeout: 300000, +}; type GetInitialReduxStateInput = { +urlInfo: URLInfo, @@ -76,7 +78,7 @@ await callKeyserverEndpoint( 'get_initial_redux_state', requests, - getInitialReduxStateCallServerEndpointOptions, + getInitialReduxStateCallSingleKeyserverEndpointOptions, ); const {