Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32400703
D9217.1765340491.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D9217.1765340491.diff
View Options
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
@@ -11,6 +11,7 @@
CallServerEndpoint,
CallServerEndpointOptions,
} from './call-server-endpoint.js';
+import { promiseAll } from './promises.js';
import { useSelector } from './redux-utils.js';
import type { PlatformDetails } from '../types/device-types.js';
import type { Endpoint } from '../types/endpoints.js';
@@ -19,28 +20,19 @@
import type { ConnectionStatus } from '../types/socket-types.js';
import type { CurrentUserInfo } from '../types/user-types.js';
-export type CallKeyserverEndpoint<Args: $ReadOnlyArray<mixed>> = (
+export type CallKeyserverEndpoint = (
endpoint: Endpoint,
- input: { +[string]: mixed },
- args: Args,
+ requests: { +[string]: mixed },
options?: ?CallServerEndpointOptions,
-) => Promise<any>;
+) => Promise<{ +[id: string]: any }>;
-export type ActionFunc<Args: $ReadOnlyArray<mixed>, Return> = (
- callServerEndpoint: CallKeyserverEndpoint<Args>,
-) => (...Args) => Promise<Return>;
-
-export type KeyserverCallConfig<Args: $ReadOnlyArray<mixed>> =
- | { +keyserverSelection: 'fanout' }
- | {
- +keyserverSelection: 'specific',
- +keyserverIDExtractor: (...Args) => string,
- };
-
-export type KeyserverCall<Args: $ReadOnlyArray<mixed>, Return> = {
- +actionFunc: ActionFunc<Args, Return>,
- +config: KeyserverCallConfig<Args>,
-};
+export type ActionFunc<Args: mixed, Return> = (
+ callServerEndpoint: CallKeyserverEndpoint,
+ // The second argument is only used in actions that call all keyservers,
+ // and the request to all keyservers are exactly the same.
+ // An example of such action is fetchEntries.
+ allKeyserverIDs: $ReadOnlyArray<string>,
+) => Args => Promise<Return>;
// _memoize memoizes the function by caching the result.
// The first argument of the memoized function is used as the map cache key.
@@ -87,11 +79,6 @@
+keyserverInfos: { +[keyserverID: string]: KeyserverInfo },
};
-export type GetCallKeyserverEndpointParams<Args: $ReadOnlyArray<mixed>> = {
- ...BindKeyserverCallParams,
- +keyserverCallConfig: KeyserverCallConfig<Args>,
-};
-
const bindCallKeyserverEndpointSelector = createSelector(
(state: BindKeyserverCallParams) => state.dispatch,
(state: BindKeyserverCallParams) => state.currentUserInfo,
@@ -102,55 +89,59 @@
keyserverInfos: { +[keyserverID: string]: KeyserverInfo },
) => {
return _memoize(
- <Args: $ReadOnlyArray<mixed>, Return>(
- keyserverCall: KeyserverCall<Args, Return>,
- ): ((...Args) => Promise<Return>) => {
+ <Args: mixed, Return>(
+ keyserverCall: ActionFunc<Args, Return>,
+ ): (Args => Promise<Return>) => {
const callKeyserverEndpoint = (
endpoint: Endpoint,
- data: Object,
- args: Args,
+ requests: { +[id: string]: Object },
options?: ?CallServerEndpointOptions,
) => {
- // TODO
- if (keyserverCall.config.keyserverSelection === 'fanout') {
- return Promise.resolve(undefined);
+ const bindCallKeyserverEndpoint = (keyserverID: string) => {
+ const {
+ cookie,
+ urlPrefix,
+ sessionID,
+ connection,
+ lastCommunicatedPlatformDetails,
+ } = keyserverInfos[keyserverID];
+
+ const boundCallServerEndpoint = createBoundServerCallsSelector(
+ keyserverID,
+ )({
+ dispatch,
+ currentUserInfo,
+ cookie,
+ urlPrefix,
+ sessionID,
+ connectionStatus: connection.status,
+ lastCommunicatedPlatformDetails,
+ });
+
+ return boundCallServerEndpoint(
+ endpoint,
+ requests[keyserverID],
+ options,
+ );
+ };
+
+ const promises = {};
+ for (const keyserverID in requests) {
+ promises[keyserverID] = bindCallKeyserverEndpoint(keyserverID);
}
- const keyserverID = keyserverCall.config.keyserverIDExtractor(
- ...args,
- );
- const {
- cookie,
- urlPrefix,
- sessionID,
- connection,
- lastCommunicatedPlatformDetails,
- } = keyserverInfos[keyserverID];
-
- const boundCallServerEndpoint = createBoundServerCallsSelector(
- keyserverID,
- )({
- dispatch,
- currentUserInfo,
- cookie,
- urlPrefix,
- sessionID,
- connectionStatus: connection.status,
- lastCommunicatedPlatformDetails,
- });
-
- return boundCallServerEndpoint(endpoint, data, options);
+ return promiseAll(promises);
};
-
- return keyserverCall.actionFunc(callKeyserverEndpoint);
+ const keyserverIDs = Object.keys(keyserverInfos);
+ return keyserverCall(callKeyserverEndpoint, keyserverIDs);
},
);
},
);
-function useKeyserverCall<Args: $ReadOnlyArray<mixed>, Return>(
- keyserverCall: KeyserverCall<Args, Return>,
+function useKeyserverCall<Args: mixed, Return>(
+ keyserverCall: ActionFunc<Args, Return>,
paramOverride?: ?$Shape<BindKeyserverCallParams>,
-): (...Args) => Promise<Return> {
+): Args => Promise<Return> {
const dispatch = useDispatch();
const keyserverInfos = useSelector(
state => state.keyserverStore.keyserverInfos,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 10, 4:21 AM (15 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5860914
Default Alt Text
D9217.1765340491.diff (5 KB)
Attached To
Mode
D9217: [lib] Add logic for handling faonut actions
Attached
Detach File
Event Timeline
Log In to Comment