Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3378925
D9368.id32620.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D9368.id32620.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
@@ -9,7 +9,10 @@
DisableInviteLinkRequest,
DisableInviteLinkPayload,
} from '../types/link-types.js';
+import { extractKeyserverIDFromID } from '../utils/action-utils.js';
import type { CallServerEndpoint } from '../utils/call-server-endpoint.js';
+import { useKeyserverCall } from '../utils/keyserver-call.js';
+import type { CallKeyserverEndpoint } from '../utils/keyserver-call.js';
const verifyInviteLinkActionTypes = Object.freeze({
started: 'VERIFY_INVITE_LINK_STARTED',
@@ -42,15 +45,34 @@
});
const fetchPrimaryInviteLinks =
(
- callServerEndpoint: CallServerEndpoint,
+ callKeyserverEndpoint: CallKeyserverEndpoint,
+ allKeyserverIDs: $ReadOnlyArray<string>,
): (() => Promise<FetchInviteLinksResponse>) =>
async () => {
- const response = await callServerEndpoint('fetch_primary_invite_links');
+ const requests = allKeyserverIDs.reduce(
+ (acc, curr) => ({
+ ...acc,
+ [curr]: undefined,
+ }),
+ {},
+ );
+ const responses = await callKeyserverEndpoint(
+ 'fetch_primary_invite_links',
+ requests,
+ );
+ let links = [];
+ for (const keyserverID in responses) {
+ links = links.concat(responses[keyserverID].links);
+ }
return {
- links: response.links,
+ links,
};
};
+function useFetchPrimaryInviteLinks(): () => Promise<FetchInviteLinksResponse> {
+ return useKeyserverCall(fetchPrimaryInviteLinks);
+}
+
const createOrUpdatePublicLinkActionTypes = Object.freeze({
started: 'CREATE_OR_UPDATE_PUBLIC_LINK_STARTED',
success: 'CREATE_OR_UPDATE_PUBLIC_LINK_SUCCESS',
@@ -59,13 +81,22 @@
const createOrUpdatePublicLink =
(
- callServerEndpoint: CallServerEndpoint,
- ): ((request: CreateOrUpdatePublicLinkRequest) => Promise<InviteLink>) =>
- async request => {
- const response = await callServerEndpoint('create_or_update_public_link', {
- name: request.name,
- communityID: request.communityID,
- });
+ callKeyserverEndpoint: CallKeyserverEndpoint,
+ ): ((input: CreateOrUpdatePublicLinkRequest) => Promise<InviteLink>) =>
+ async input => {
+ const keyserverID = extractKeyserverIDFromID(input.communityID);
+ const requests = {
+ [keyserverID]: {
+ name: input.name,
+ communityID: input.communityID,
+ },
+ };
+
+ const responses = await callKeyserverEndpoint(
+ 'create_or_update_public_link',
+ requests,
+ );
+ const response = responses[keyserverID];
return {
name: response.name,
primary: response.primary,
@@ -77,6 +108,12 @@
};
};
+function useCreateOrUpdatePublicLink(): (
+ input: CreateOrUpdatePublicLinkRequest,
+) => Promise<InviteLink> {
+ return useKeyserverCall(createOrUpdatePublicLink);
+}
+
const disableInviteLinkLinkActionTypes = Object.freeze({
started: 'DISABLE_INVITE_LINK_STARTED',
success: 'DISABLE_INVITE_LINK_SUCCESS',
@@ -85,25 +122,29 @@
const disableInviteLink =
(
- callServerEndpoint: CallServerEndpoint,
- ): ((
- request: DisableInviteLinkRequest,
- ) => Promise<DisableInviteLinkPayload>) =>
- async request => {
- await callServerEndpoint('disable_invite_link', request);
- return {
- name: request.name,
- communityID: request.communityID,
- };
+ callKeyserverEndpoint: CallKeyserverEndpoint,
+ ): ((input: DisableInviteLinkRequest) => Promise<DisableInviteLinkPayload>) =>
+ async input => {
+ const keyserverID = extractKeyserverIDFromID(input.communityID);
+ const requests = { [keyserverID]: input };
+
+ await callKeyserverEndpoint('disable_invite_link', requests);
+ return input;
};
+function useDisableInviteLink(): (
+ input: DisableInviteLinkRequest,
+) => Promise<DisableInviteLinkPayload> {
+ return useKeyserverCall(disableInviteLink);
+}
+
export {
verifyInviteLinkActionTypes,
verifyInviteLink,
fetchPrimaryInviteLinkActionTypes,
- fetchPrimaryInviteLinks,
+ useFetchPrimaryInviteLinks,
createOrUpdatePublicLinkActionTypes,
- createOrUpdatePublicLink,
+ useCreateOrUpdatePublicLink,
disableInviteLinkLinkActionTypes,
- disableInviteLink,
+ useDisableInviteLink,
};
diff --git a/lib/hooks/invite-links.js b/lib/hooks/invite-links.js
--- a/lib/hooks/invite-links.js
+++ b/lib/hooks/invite-links.js
@@ -3,18 +3,15 @@
import React from 'react';
import {
- createOrUpdatePublicLink,
+ useCreateOrUpdatePublicLink,
createOrUpdatePublicLinkActionTypes,
- disableInviteLink as callDisableInviteLink,
+ useDisableInviteLink,
disableInviteLinkLinkActionTypes,
} from '../actions/link-actions.js';
import { createLoadingStatusSelector } from '../selectors/loading-selectors.js';
import type { SetState } from '../types/hook-types.js';
import type { InviteLink } from '../types/link-types.js';
-import {
- useDispatchActionPromise,
- useServerCall,
-} from '../utils/action-utils.js';
+import { useDispatchActionPromise } from '../utils/action-utils.js';
import { useSelector } from '../utils/redux-utils.js';
const createOrUpdatePublicLinkStatusSelector = createLoadingStatusSelector(
@@ -41,7 +38,7 @@
const [error, setError] = React.useState(null);
const dispatchActionPromise = useDispatchActionPromise();
- const callCreateOrUpdatePublicLink = useServerCall(createOrUpdatePublicLink);
+ const callCreateOrUpdatePublicLink = useCreateOrUpdatePublicLink();
const createCreateOrUpdateActionPromise = React.useCallback(async () => {
setError(null);
try {
@@ -61,7 +58,7 @@
);
}, [createCreateOrUpdateActionPromise, dispatchActionPromise]);
- const disableInviteLinkServerCall = useServerCall(callDisableInviteLink);
+ const disableInviteLinkServerCall = useDisableInviteLink();
const createDisableLinkActionPromise = React.useCallback(async () => {
setError(null);
try {
diff --git a/native/navigation/community-drawer-content.react.js b/native/navigation/community-drawer-content.react.js
--- a/native/navigation/community-drawer-content.react.js
+++ b/native/navigation/community-drawer-content.react.js
@@ -9,17 +9,14 @@
import {
fetchPrimaryInviteLinkActionTypes,
- fetchPrimaryInviteLinks,
+ useFetchPrimaryInviteLinks,
} from 'lib/actions/link-actions.js';
import {
childThreadInfos,
communityThreadSelector,
} from 'lib/selectors/thread-selectors.js';
import { threadTypeIsCommunityRoot } from 'lib/types/thread-types-enum.js';
-import {
- useDispatchActionPromise,
- useServerCall,
-} from 'lib/utils/action-utils.js';
+import { useDispatchActionPromise } from 'lib/utils/action-utils.js';
import {
createRecursiveDrawerItemsData,
appendSuffix,
@@ -51,7 +48,7 @@
);
const styles = useStyles(unboundStyles);
- const callFetchPrimaryLinks = useServerCall(fetchPrimaryInviteLinks);
+ const callFetchPrimaryLinks = useFetchPrimaryInviteLinks();
const dispatchActionPromise = useDispatchActionPromise();
const drawerStatus = useDrawerStatus();
React.useEffect(() => {
diff --git a/web/invite-links/invite-links-refresher.react.js b/web/invite-links/invite-links-refresher.react.js
--- a/web/invite-links/invite-links-refresher.react.js
+++ b/web/invite-links/invite-links-refresher.react.js
@@ -4,20 +4,17 @@
import {
fetchPrimaryInviteLinkActionTypes,
- fetchPrimaryInviteLinks,
+ useFetchPrimaryInviteLinks,
} from 'lib/actions/link-actions.js';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
-import {
- useDispatchActionPromise,
- useServerCall,
-} from 'lib/utils/action-utils.js';
+import { useDispatchActionPromise } from 'lib/utils/action-utils.js';
import { useSelector } from '../redux/redux-utils.js';
function InviteLinksRefresher(): React.Node {
const isActive = useSelector(state => state.windowActive);
const loggedIn = useSelector(isLoggedIn);
- const callFetchPrimaryLinks = useServerCall(fetchPrimaryInviteLinks);
+ const callFetchPrimaryLinks = useFetchPrimaryInviteLinks();
const dispatchActionPromise = useDispatchActionPromise();
React.useEffect(() => {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 2:01 PM (20 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2594169
Default Alt Text
D9368.id32620.diff (7 KB)
Attached To
Mode
D9368: [lib][web][native] Refactor actions in link-actions.js
Attached
Detach File
Event Timeline
Log In to Comment