Page MenuHomePhabricator

D10311.id36530.diff
No OneTemporary

D10311.id36530.diff

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
@@ -50,35 +50,41 @@
};
};
-function useVerifyInviteLink(keyserverOverride?: {
- +keyserverID: string,
- +keyserverURL: string,
-}): (
+function useVerifyInviteLink(): (
request: InviteLinkVerificationRequest,
+ keyserverOverride?: ?{
+ +keyserverID: string,
+ +keyserverURL: string,
+ },
) => Promise<InviteLinkVerificationResponse> {
- const keyserverID = keyserverOverride?.keyserverID ?? ashoatKeyserverID;
- const isKeyserverKnown = useSelector(
- state => !!state.keyserverStore.keyserverInfos[keyserverID],
- );
-
- let paramOverride = null;
- if (keyserverOverride && !isKeyserverKnown) {
- paramOverride = {
- keyserverInfos: {
- [keyserverOverride.keyserverID]: {
- urlPrefix: keyserverOverride.keyserverURL,
- },
- },
- };
- }
- const callVerifyInviteLink = useKeyserverCall(
- verifyInviteLink,
- paramOverride,
+ const callVerifyInviteLink = useKeyserverCall(verifyInviteLink);
+ const keyserverInfos = useSelector(
+ state => state.keyserverStore.keyserverInfos,
);
return React.useCallback(
- (request: InviteLinkVerificationRequest) =>
- callVerifyInviteLink({ request, keyserverID }),
- [callVerifyInviteLink, keyserverID],
+ (
+ request: InviteLinkVerificationRequest,
+ keyserverOverride?: ?{
+ +keyserverID: string,
+ +keyserverURL: string,
+ },
+ ) => {
+ const keyserverID = keyserverOverride?.keyserverID ?? ashoatKeyserverID;
+ const isKeyserverKnown = !!keyserverInfos[keyserverID];
+
+ let paramOverride = null;
+ if (keyserverOverride && !isKeyserverKnown) {
+ paramOverride = {
+ keyserverInfos: {
+ [keyserverOverride.keyserverID]: {
+ urlPrefix: keyserverOverride.keyserverURL,
+ },
+ },
+ };
+ }
+ return callVerifyInviteLink({ request, keyserverID }, paramOverride);
+ },
+ [callVerifyInviteLink, keyserverInfos],
);
}
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
@@ -25,7 +25,7 @@
function useKeyserverCall<Args: mixed, Return>(
keyserverCall: ActionFunc<Args, Return>,
paramOverride?: ?KeyserverCallParamOverride,
-): Args => Promise<Return> {
+): (Args, ?KeyserverCallParamOverride) => Promise<Return> {
const baseDispatch = useDispatch();
const baseCurrentUserInfo = useSelector(state => state.currentUserInfo);
@@ -66,46 +66,56 @@
return cachedNonOverridenBoundKeyserverCall;
}
- const callKeyserverEndpoint = (
- endpoint: Endpoint,
- requests: { +[keyserverID: string]: ?{ +[string]: mixed } },
- options?: ?CallSingleKeyserverEndpointOptions,
- ) => {
- const makeCallToSingleKeyserver = (keyserverID: string) => {
- const {
- cookie,
- urlPrefix,
- sessionID,
- isSocketConnected,
- lastCommunicatedPlatformDetails,
- } = keyserverCallInfos[keyserverID];
-
- const boundCallSingleKeyserverEndpoint =
- getCallSingleKeyserverEndpointSelector(keyserverID)({
- dispatch,
- currentUserInfo,
+ const callKeyserverEndpoint =
+ (overrides?: ?KeyserverCallParamOverride) =>
+ (
+ endpoint: Endpoint,
+ requests: { +[keyserverID: string]: ?{ +[string]: mixed } },
+ options?: ?CallSingleKeyserverEndpointOptions,
+ ) => {
+ const makeCallToSingleKeyserver = (keyserverID: string) => {
+ const {
cookie,
urlPrefix,
sessionID,
isSocketConnected,
lastCommunicatedPlatformDetails,
- });
+ } = {
+ ...keyserverCallInfos[keyserverID],
+ ...overrides?.keyserverInfos?.[keyserverID],
+ };
- return boundCallSingleKeyserverEndpoint(
- endpoint,
- requests[keyserverID],
- options,
- );
- };
+ const boundCallSingleKeyserverEndpoint =
+ getCallSingleKeyserverEndpointSelector(keyserverID)({
+ dispatch,
+ currentUserInfo,
+ cookie,
+ urlPrefix,
+ sessionID,
+ isSocketConnected,
+ lastCommunicatedPlatformDetails,
+ });
- const promises: { [string]: Promise<Object> } = {};
- for (const keyserverID in requests) {
- promises[keyserverID] = makeCallToSingleKeyserver(keyserverID);
- }
- return promiseAll(promises);
- };
+ return boundCallSingleKeyserverEndpoint(
+ endpoint,
+ requests[keyserverID],
+ options,
+ );
+ };
+
+ const promises: { [string]: Promise<Object> } = {};
+ for (const keyserverID in requests) {
+ promises[keyserverID] = makeCallToSingleKeyserver(keyserverID);
+ }
+ return promiseAll(promises);
+ };
const keyserverIDs = Object.keys(keyserverCallInfos);
- return keyserverCall(callKeyserverEndpoint, keyserverIDs);
+ return (args: Args, overrides?: ?KeyserverCallParamOverride) => {
+ return keyserverCall(
+ callKeyserverEndpoint(overrides),
+ keyserverIDs,
+ )(args);
+ };
}, [
paramOverride,
cachedNonOverridenBoundKeyserverCall,

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 5:39 AM (12 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2698531
Default Alt Text
D10311.id36530.diff (5 KB)

Event Timeline