Page MenuHomePhabricator

D11089.diff
No OneTemporary

D11089.diff

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
@@ -53,6 +53,10 @@
+createCallSingleKeyserverEndpointSelector: CreateCallSingleKeyserverEndpointSelector,
+getBoundSingleKeyserverActionFunc: GetBoundSingleKeyserverActionFunc,
+getBoundKeyserverActionFunc: GetBoundKeyserverActionFunc,
+ +registerActiveSocket: (
+ keyserverID: string,
+ socketAPIHandler: ?SocketAPIHandler,
+ ) => mixed,
};
const CallKeyserverEndpointContext: React.Context<?CallKeyserverEndpointContextType> =
@@ -90,6 +94,16 @@
Map<string, OngoingRecoveryAttempt>,
>(new Map());
+ const socketAPIHandlers = React.useRef<Map<string, ?SocketAPIHandler>>(
+ new Map(),
+ );
+
+ const registerActiveSocket = React.useCallback(
+ (keyserverID: string, socketAPIHandler: ?SocketAPIHandler) =>
+ socketAPIHandlers.current.set(keyserverID, socketAPIHandler),
+ [],
+ );
+
const bindCookieAndUtilsIntoCallSingleKeyserverEndpoint: (
params: BindServerCallsParams,
) => CallSingleKeyserverEndpoint = React.useCallback(params => {
@@ -229,7 +243,7 @@
sessionID,
isSocketConnected,
lastCommunicatedPlatformDetails,
- socketAPIHandler,
+ socketAPIHandlers.current.get(keyserverID),
endpoint,
data,
dispatch,
@@ -417,11 +431,13 @@
createCallSingleKeyserverEndpointSelector,
getBoundSingleKeyserverActionFunc,
getBoundKeyserverActionFunc,
+ registerActiveSocket,
}),
[
createCallSingleKeyserverEndpointSelector,
getBoundSingleKeyserverActionFunc,
getBoundKeyserverActionFunc,
+ registerActiveSocket,
],
);
@@ -443,13 +459,4 @@
return callKeyserverEndpointContext;
}
-let socketAPIHandler: ?SocketAPIHandler = null;
-function registerActiveSocket(passedSocketAPIHandler: ?SocketAPIHandler) {
- socketAPIHandler = passedSocketAPIHandler;
-}
-
-export {
- CallKeyserverEndpointProvider,
- useCallKeyserverEndpointContext,
- registerActiveSocket,
-};
+export { CallKeyserverEndpointProvider, useCallKeyserverEndpointContext };
diff --git a/lib/socket/api-request-handler.react.js b/lib/socket/api-request-handler.react.js
--- a/lib/socket/api-request-handler.react.js
+++ b/lib/socket/api-request-handler.react.js
@@ -4,9 +4,9 @@
import * as React from 'react';
import { InflightRequests } from './inflight-requests.js';
-import { registerActiveSocket } from '../keyserver-conn/call-keyserver-endpoint-provider.react.js';
+import { useCallKeyserverEndpointContext } from '../keyserver-conn/call-keyserver-endpoint-provider.react.js';
import { connectionSelector } from '../selectors/keyserver-selectors.js';
-import type { APIRequest } from '../types/endpoints.js';
+import type { APIRequest, SocketAPIHandler } from '../types/endpoints.js';
import {
clientSocketMessageTypes,
serverSocketMessageTypes,
@@ -16,15 +16,19 @@
} from '../types/socket-types.js';
import { SocketOffline } from '../utils/errors.js';
import { useSelector } from '../utils/redux-utils.js';
-import { ashoatKeyserverID } from '../utils/validation-utils.js';
type BaseProps = {
+inflightRequests: ?InflightRequests,
+sendMessage: (message: ClientSocketMessageWithoutID) => number,
+ +keyserverID: string,
};
type Props = {
...BaseProps,
+connection: ConnectionInfo,
+ +registerActiveSocket: (
+ keyserverID: string,
+ socketAPIHandler: ?SocketAPIHandler,
+ ) => mixed,
};
class APIRequestHandler extends React.PureComponent<Props> {
static isConnected(props: Props, request?: APIRequest): boolean {
@@ -49,25 +53,31 @@
);
}
- get registeredResponseFetcher(): ?(request: APIRequest) => Promise<mixed> {
+ get registeredResponseFetcher(): ?SocketAPIHandler {
return APIRequestHandler.isConnected(this.props)
? this.fetchResponse
: null;
}
componentDidMount() {
- registerActiveSocket(this.registeredResponseFetcher);
+ this.props.registerActiveSocket(
+ this.props.keyserverID,
+ this.registeredResponseFetcher,
+ );
}
componentWillUnmount() {
- registerActiveSocket(null);
+ this.props.registerActiveSocket(this.props.keyserverID, null);
}
componentDidUpdate(prevProps: Props) {
const isConnected = APIRequestHandler.isConnected(this.props);
const wasConnected = APIRequestHandler.isConnected(prevProps);
if (isConnected !== wasConnected) {
- registerActiveSocket(this.registeredResponseFetcher);
+ this.props.registerActiveSocket(
+ this.props.keyserverID,
+ this.registeredResponseFetcher,
+ );
}
}
@@ -96,9 +106,16 @@
const ConnectedAPIRequestHandler: React.ComponentType<BaseProps> =
React.memo<BaseProps>(function ConnectedAPIRequestHandler(props) {
- const connection = useSelector(connectionSelector(ashoatKeyserverID));
+ const connection = useSelector(connectionSelector(props.keyserverID));
invariant(connection, 'keyserver missing from keyserverStore');
- return <APIRequestHandler {...props} connection={connection} />;
+ const { registerActiveSocket } = useCallKeyserverEndpointContext();
+ return (
+ <APIRequestHandler
+ {...props}
+ connection={connection}
+ registerActiveSocket={registerActiveSocket}
+ />
+ );
});
export default ConnectedAPIRequestHandler;
diff --git a/lib/socket/socket.react.js b/lib/socket/socket.react.js
--- a/lib/socket/socket.react.js
+++ b/lib/socket/socket.react.js
@@ -344,6 +344,7 @@
<APIRequestHandler
inflightRequests={this.state.inflightRequests}
sendMessage={this.sendMessageWithoutID}
+ keyserverID={this.props.keyserverID}
/>
<ActivityHandler
activeThread={this.props.activeThread}

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 9, 10:40 AM (9 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2833601
Default Alt Text
D11089.diff (5 KB)

Event Timeline