Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3522049
D10338.id36531.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D10338.id36531.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
@@ -3,6 +3,7 @@
import { extractKeyserverIDFromID } from '../keyserver-conn/keyserver-call-utils.js';
import type { CallKeyserverEndpoint } from '../keyserver-conn/keyserver-conn-types.js';
+import type { KeyserverOverride } from '../shared/invite-links.js';
import type {
FetchInviteLinksResponse,
InviteLinkVerificationRequest,
@@ -52,10 +53,7 @@
function useVerifyInviteLink(): (
request: InviteLinkVerificationRequest,
- keyserverOverride?: ?{
- +keyserverID: string,
- +keyserverURL: string,
- },
+ keyserverOverride?: ?KeyserverOverride,
) => Promise<InviteLinkVerificationResponse> {
const callVerifyInviteLink = useKeyserverCall(verifyInviteLink);
const keyserverInfos = useSelector(
@@ -64,10 +62,7 @@
return React.useCallback(
(
request: InviteLinkVerificationRequest,
- keyserverOverride?: ?{
- +keyserverID: string,
- +keyserverURL: string,
- },
+ keyserverOverride?: ?KeyserverOverride,
) => {
const keyserverID = keyserverOverride?.keyserverID ?? ashoatKeyserverID;
const isKeyserverKnown = !!keyserverInfos[keyserverID];
diff --git a/lib/shared/invite-links.js b/lib/shared/invite-links.js
--- a/lib/shared/invite-links.js
+++ b/lib/shared/invite-links.js
@@ -1,5 +1,8 @@
// @flow
+import blobService from '../facts/blob-service.js';
+import { getBlobFetchableURL } from '../utils/blob-service.js';
+
const inviteLinkErrorMessages: { +[string]: string } = {
invalid_characters: 'Link cannot contain any spaces or special characters.',
offensive_words: 'No offensive or abusive words allowed.',
@@ -15,4 +18,36 @@
return `invite_${secret}`;
}
-export { inviteLinkErrorMessages, defaultErrorMessage, inviteLinkBlobHash };
+export type KeyserverOverride = {
+ +keyserverID: string,
+ +keyserverURL: string,
+};
+
+async function getKeyserverOverrideForAnInviteLink(
+ secret: string,
+): Promise<?KeyserverOverride> {
+ const blobURL = getBlobFetchableURL(inviteLinkBlobHash(secret));
+ const result = await fetch(blobURL, {
+ method: blobService.httpEndpoints.GET_BLOB.method,
+ });
+ if (result.status !== 200) {
+ return null;
+ }
+ const resultText = await result.text();
+ const resultObject = JSON.parse(resultText);
+ if (resultObject.keyserverID && resultObject.keyserverURL) {
+ const keyserverURL: string = resultObject.keyserverURL;
+ return {
+ keyserverID: resultObject.keyserverID,
+ keyserverURL: keyserverURL.replace(/\/$/, ''),
+ };
+ }
+ return null;
+}
+
+export {
+ inviteLinkErrorMessages,
+ defaultErrorMessage,
+ inviteLinkBlobHash,
+ getKeyserverOverrideForAnInviteLink,
+};
diff --git a/native/navigation/deep-links-context-provider.react.js b/native/navigation/deep-links-context-provider.react.js
--- a/native/navigation/deep-links-context-provider.react.js
+++ b/native/navigation/deep-links-context-provider.react.js
@@ -15,6 +15,7 @@
type ParsedDeepLinkData,
} from 'lib/facts/links.js';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
+import { getKeyserverOverrideForAnInviteLink } from 'lib/shared/invite-links.js';
import type { SetState } from 'lib/types/hook-types.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
@@ -99,14 +100,27 @@
if (parsedData.type === 'invite-link') {
const { secret } = parsedData.data;
- const validateLinkPromise = validateLink({ secret });
- void dispatchActionPromise(
- verifyInviteLinkActionTypes,
- validateLinkPromise,
- );
- const result = await validateLinkPromise;
- if (result.status === 'already_joined') {
- return;
+ let result;
+ try {
+ const keyserverOverride =
+ await getKeyserverOverrideForAnInviteLink(secret);
+ const validateLinkPromise = validateLink(
+ { secret },
+ keyserverOverride,
+ );
+ void dispatchActionPromise(
+ verifyInviteLinkActionTypes,
+ validateLinkPromise,
+ );
+ result = await validateLinkPromise;
+ if (result.status === 'already_joined') {
+ return;
+ }
+ } catch (e) {
+ console.log(e);
+ result = {
+ status: 'invalid',
+ };
}
navigation.navigate<'InviteLinkModal'>({
diff --git a/web/invite-links/invite-link-handler.react.js b/web/invite-links/invite-link-handler.react.js
--- a/web/invite-links/invite-link-handler.react.js
+++ b/web/invite-links/invite-link-handler.react.js
@@ -8,6 +8,7 @@
} from 'lib/actions/link-actions.js';
import { useModalContext } from 'lib/components/modal-provider.react.js';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
+import { getKeyserverOverrideForAnInviteLink } from 'lib/shared/invite-links.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
@@ -24,23 +25,39 @@
const validateLink = useVerifyInviteLink();
const { pushModal } = useModalContext();
React.useEffect(() => {
- if (!inviteSecret || !loggedIn) {
- return;
- }
- dispatch({
- type: updateNavInfoActionType,
- payload: { inviteSecret: null },
- });
- const validateLinkPromise = validateLink({ secret: inviteSecret });
- void dispatchActionPromise(
- verifyInviteLinkActionTypes,
- validateLinkPromise,
- );
void (async () => {
- const result = await validateLinkPromise;
- if (result.status === 'already_joined') {
+ if (!inviteSecret || !loggedIn) {
return;
}
+ dispatch({
+ type: updateNavInfoActionType,
+ payload: { inviteSecret: null },
+ });
+
+ let result;
+ try {
+ const keyserverOverride =
+ await getKeyserverOverrideForAnInviteLink(inviteSecret);
+ const validateLinkPromise = validateLink(
+ { secret: inviteSecret },
+ keyserverOverride,
+ );
+ void dispatchActionPromise(
+ verifyInviteLinkActionTypes,
+ validateLinkPromise,
+ );
+
+ result = await validateLinkPromise;
+ if (result.status === 'already_joined') {
+ return;
+ }
+ } catch (e) {
+ console.error(e);
+ result = {
+ status: 'invalid',
+ };
+ }
+
pushModal(
<AcceptInviteModal
verificationResponse={result}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 5:39 AM (18 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2698537
Default Alt Text
D10338.id36531.diff (6 KB)
Attached To
Mode
D10338: [web][native] Download invite link blob and use it as an override
Attached
Detach File
Event Timeline
Log In to Comment