Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3527415
D10311.id36530.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D10311.id36530.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 25, 5:04 AM (9 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2698531
Default Alt Text
D10311.id36530.diff (5 KB)
Attached To
Mode
D10311: [lib] Allow overriding a keyserver in a function returned from useKeyserverCall hook
Attached
Detach File
Event Timeline
Log In to Comment