Changeset View
Changeset View
Standalone View
Standalone View
lib/utils/keyserver-call.js
Show All 10 Lines | import type { | ||||
CallServerEndpointOptions, | CallServerEndpointOptions, | ||||
} from './call-server-endpoint.js'; | } from './call-server-endpoint.js'; | ||||
import { promiseAll } from './promises.js'; | import { promiseAll } from './promises.js'; | ||||
import { useSelector, useDispatch } from './redux-utils.js'; | import { useSelector, useDispatch } from './redux-utils.js'; | ||||
import type { PlatformDetails } from '../types/device-types.js'; | import type { PlatformDetails } from '../types/device-types.js'; | ||||
import type { Endpoint } from '../types/endpoints.js'; | import type { Endpoint } from '../types/endpoints.js'; | ||||
import type { KeyserverInfo } from '../types/keyserver-types.js'; | import type { KeyserverInfo } from '../types/keyserver-types.js'; | ||||
import type { Dispatch } from '../types/redux-types.js'; | import type { Dispatch } from '../types/redux-types.js'; | ||||
import type { ConnectionStatus } from '../types/socket-types.js'; | |||||
import type { CurrentUserInfo } from '../types/user-types.js'; | import type { CurrentUserInfo } from '../types/user-types.js'; | ||||
export type CallKeyserverEndpoint = ( | export type CallKeyserverEndpoint = ( | ||||
endpoint: Endpoint, | endpoint: Endpoint, | ||||
requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, | requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, | ||||
options?: ?CallServerEndpointOptions, | options?: ?CallServerEndpointOptions, | ||||
) => Promise<{ +[keyserverID: string]: any }>; | ) => Promise<{ +[keyserverID: string]: any }>; | ||||
Show All 12 Lines | const baseCreateBoundServerCallsSelector = ( | ||||
keyserverID: string, | keyserverID: string, | ||||
): (BindServerCallsParams => CallServerEndpoint) => | ): (BindServerCallsParams => CallServerEndpoint) => | ||||
createSelector( | createSelector( | ||||
(state: BindServerCallsParams) => state.dispatch, | (state: BindServerCallsParams) => state.dispatch, | ||||
(state: BindServerCallsParams) => state.cookie, | (state: BindServerCallsParams) => state.cookie, | ||||
(state: BindServerCallsParams) => state.urlPrefix, | (state: BindServerCallsParams) => state.urlPrefix, | ||||
(state: BindServerCallsParams) => state.sessionID, | (state: BindServerCallsParams) => state.sessionID, | ||||
(state: BindServerCallsParams) => state.currentUserInfo, | (state: BindServerCallsParams) => state.currentUserInfo, | ||||
(state: BindServerCallsParams) => state.connectionStatus, | (state: BindServerCallsParams) => state.isSocketConnected, | ||||
(state: BindServerCallsParams) => state.lastCommunicatedPlatformDetails, | (state: BindServerCallsParams) => state.lastCommunicatedPlatformDetails, | ||||
( | ( | ||||
dispatch: Dispatch, | dispatch: Dispatch, | ||||
cookie: ?string, | cookie: ?string, | ||||
urlPrefix: string, | urlPrefix: string, | ||||
sessionID: ?string, | sessionID: ?string, | ||||
currentUserInfo: ?CurrentUserInfo, | currentUserInfo: ?CurrentUserInfo, | ||||
connectionStatus: ConnectionStatus, | isSocketConnected: boolean, | ||||
lastCommunicatedPlatformDetails: ?PlatformDetails, | lastCommunicatedPlatformDetails: ?PlatformDetails, | ||||
) => | ) => | ||||
bindCookieAndUtilsIntoCallServerEndpoint({ | bindCookieAndUtilsIntoCallServerEndpoint({ | ||||
dispatch, | dispatch, | ||||
cookie, | cookie, | ||||
urlPrefix, | urlPrefix, | ||||
sessionID, | sessionID, | ||||
currentUserInfo, | currentUserInfo, | ||||
connectionStatus, | isSocketConnected, | ||||
lastCommunicatedPlatformDetails, | lastCommunicatedPlatformDetails, | ||||
keyserverID, | keyserverID, | ||||
}), | }), | ||||
); | ); | ||||
type CreateBoundServerCallsSelectorType = ( | type CreateBoundServerCallsSelectorType = ( | ||||
keyserverID: string, | keyserverID: string, | ||||
) => BindServerCallsParams => CallServerEndpoint; | ) => BindServerCallsParams => CallServerEndpoint; | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | return _memoize( | ||||
const boundCallServerEndpoint = createBoundServerCallsSelector( | const boundCallServerEndpoint = createBoundServerCallsSelector( | ||||
keyserverID, | keyserverID, | ||||
)({ | )({ | ||||
dispatch, | dispatch, | ||||
currentUserInfo, | currentUserInfo, | ||||
cookie, | cookie, | ||||
urlPrefix, | urlPrefix, | ||||
sessionID, | sessionID, | ||||
connectionStatus: connection?.status ?? 'disconnected', | isSocketConnected: connection?.status === 'connected', | ||||
lastCommunicatedPlatformDetails, | lastCommunicatedPlatformDetails, | ||||
keyserverID, | keyserverID, | ||||
}); | }); | ||||
return boundCallServerEndpoint( | return boundCallServerEndpoint( | ||||
endpoint, | endpoint, | ||||
requests[keyserverID], | requests[keyserverID], | ||||
options, | options, | ||||
Show All 40 Lines |