Page MenuHomePhabricator

D10311.id34565.diff
No OneTemporary

D10311.id34565.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
@@ -49,35 +49,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
@@ -90,7 +90,7 @@
Return,
>(
keyserverCall: ActionFunc<Args, Return>,
-) => Args => Promise<Return> = createSelector(
+) => (Args, ?KeyserverCallParamOverride) => Promise<Return> = createSelector(
(state: BindKeyserverCallParams) => state.dispatch,
(state: BindKeyserverCallParams) => state.currentUserInfo,
(state: BindKeyserverCallParams) => state.keyserverInfos,
@@ -102,49 +102,59 @@
return _memoize(
<Args: mixed, Return>(
keyserverCall: ActionFunc<Args, Return>,
- ): (Args => Promise<Return>) => {
- const callKeyserverEndpoint = (
- endpoint: Endpoint,
- requests: { +[keyserverID: string]: ?{ +[string]: mixed } },
- options?: ?CallServerEndpointOptions,
- ) => {
- const bindCallKeyserverEndpoint = (keyserverID: string) => {
- const {
- cookie,
- urlPrefix,
- sessionID,
- connection,
- lastCommunicatedPlatformDetails,
- } = keyserverInfos[keyserverID];
+ ): ((Args, ?KeyserverCallParamOverride) => Promise<Return>) => {
+ const callKeyserverEndpoint =
+ (overrides?: ?KeyserverCallParamOverride) =>
+ (
+ endpoint: Endpoint,
+ requests: { +[keyserverID: string]: ?{ +[string]: mixed } },
+ options?: ?CallServerEndpointOptions,
+ ) => {
+ const bindCallKeyserverEndpoint = (keyserverID: string) => {
+ const {
+ cookie,
+ urlPrefix,
+ sessionID,
+ connection,
+ lastCommunicatedPlatformDetails,
+ } = {
+ ...keyserverInfos[keyserverID],
+ ...overrides?.keyserverInfos?.[keyserverID],
+ };
- const boundCallServerEndpoint = createBoundServerCallsSelector(
- keyserverID,
- )({
- dispatch,
- currentUserInfo,
- cookie,
- urlPrefix,
- sessionID,
- connectionStatus: connection?.status ?? 'disconnected',
- lastCommunicatedPlatformDetails,
- keyserverID,
- });
+ const boundCallServerEndpoint = createBoundServerCallsSelector(
+ keyserverID,
+ )({
+ dispatch,
+ currentUserInfo,
+ cookie,
+ urlPrefix,
+ sessionID,
+ connectionStatus: connection?.status ?? 'disconnected',
+ lastCommunicatedPlatformDetails,
+ keyserverID,
+ });
- return boundCallServerEndpoint(
- endpoint,
- requests[keyserverID],
- options,
- );
- };
+ return boundCallServerEndpoint(
+ endpoint,
+ requests[keyserverID],
+ options,
+ );
+ };
- const promises: { [string]: Promise<CallServerEndpoint> } = {};
- for (const keyserverID in requests) {
- promises[keyserverID] = bindCallKeyserverEndpoint(keyserverID);
- }
- return promiseAll(promises);
- };
+ const promises: { [string]: Promise<CallServerEndpoint> } = {};
+ for (const keyserverID in requests) {
+ promises[keyserverID] = bindCallKeyserverEndpoint(keyserverID);
+ }
+ return promiseAll(promises);
+ };
const keyserverIDs = Object.keys(keyserverInfos);
- return keyserverCall(callKeyserverEndpoint, keyserverIDs);
+ return (args: Args, overrides?: ?KeyserverCallParamOverride) => {
+ return keyserverCall(
+ callKeyserverEndpoint(overrides),
+ keyserverIDs,
+ )(args);
+ };
},
);
},
@@ -155,7 +165,7 @@
function useKeyserverCall<Args: mixed, Return>(
keyserverCall: ActionFunc<Args, Return>,
paramOverride?: ?KeyserverCallParamOverride,
-): Args => Promise<Return> {
+): (Args, ?KeyserverCallParamOverride) => Promise<Return> {
const dispatch = useDispatch();
const keyserverInfos = useSelector(
state => state.keyserverStore.keyserverInfos,

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 25, 4:12 AM (9 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2698541
Default Alt Text
D10311.id34565.diff (6 KB)

Event Timeline