Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3524382
D8637.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
D8637.diff
View Options
diff --git a/native/navigation/invite-link-handler.react.js b/native/invite-links/invite-links-context-provider.react.js
rename from native/navigation/invite-link-handler.react.js
rename to native/invite-links/invite-links-context-provider.react.js
--- a/native/navigation/invite-link-handler.react.js
+++ b/native/invite-links/invite-links-context-provider.react.js
@@ -10,16 +10,32 @@
verifyInviteLinkActionTypes,
} from 'lib/actions/link-actions.js';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
+import type { SetState } from 'lib/types/hook-types.js';
import {
useDispatchActionPromise,
useServerCall,
} from 'lib/utils/action-utils.js';
-import { InviteLinkModalRouteName } from './route-names.js';
+import { InviteLinkModalRouteName } from '../navigation/route-names.js';
import { useSelector } from '../redux/redux-utils.js';
import { useOnFirstLaunchEffect } from '../utils/hooks.js';
-function InviteLinkHandler(): null {
+type InviteLinksContextType = {
+ +setCurrentLinkUrl: SetState<?string>,
+};
+
+const defaultContext = {
+ setCurrentLinkUrl: () => {},
+};
+
+const InviteLinksContext: React.Context<InviteLinksContextType> =
+ React.createContext<InviteLinksContextType>(defaultContext);
+
+type Props = {
+ +children: React.Node,
+};
+function InviteLinksContextProvider(props: Props): React.Node {
+ const { children } = props;
const [currentLink, setCurrentLink] = React.useState(null);
React.useEffect(() => {
@@ -93,7 +109,18 @@
})();
}, [currentLink, dispatchActionPromise, loggedIn, navigation, validateLink]);
- return null;
+ const contextValue = React.useMemo(
+ () => ({
+ setCurrentLinkUrl: setCurrentLink,
+ }),
+ [],
+ );
+
+ return (
+ <InviteLinksContext.Provider value={contextValue}>
+ {children}
+ </InviteLinksContext.Provider>
+ );
}
const urlRegex = /invite\/(\S+)$/;
@@ -108,4 +135,4 @@
return match?.[1];
}
-export default InviteLinkHandler;
+export { InviteLinksContext, InviteLinksContextProvider };
diff --git a/native/markdown/markdown-link.react.js b/native/markdown/markdown-link.react.js
--- a/native/markdown/markdown-link.react.js
+++ b/native/markdown/markdown-link.react.js
@@ -4,6 +4,8 @@
import * as React from 'react';
import { Text, Linking, Alert } from 'react-native';
+import { inviteLinkUrl } from 'lib/facts/links.js';
+
import {
MarkdownContext,
type MarkdownContextType,
@@ -11,9 +13,10 @@
import { MarkdownSpoilerContext } from './markdown-spoiler-context.js';
import { MessagePressResponderContext } from '../chat/message-press-responder-context.js';
import { TextMessageMarkdownContext } from '../chat/text-message-markdown-context.js';
+import { InviteLinksContext } from '../invite-links/invite-links-context-provider.react.js';
import { normalizeURL } from '../utils/url-utils.js';
-function useDisplayLinkPrompt(
+function useHandleLinkClick(
inputURL: string,
markdownContext: MarkdownContextType,
messageKey: ?string,
@@ -33,7 +36,13 @@
if (url.length > displayURL.length) {
displayURL += '…';
}
+
+ const inviteLinksContext = React.useContext(InviteLinksContext);
return React.useCallback(() => {
+ if (url.startsWith(inviteLinkUrl(''))) {
+ inviteLinksContext?.setCurrentLinkUrl(url);
+ return;
+ }
messageKey && setLinkModalActive({ [messageKey]: true });
Alert.alert(
'External link',
@@ -44,7 +53,15 @@
],
{ cancelable: true, onDismiss },
);
- }, [setLinkModalActive, messageKey, displayURL, onConfirm, onDismiss]);
+ }, [
+ url,
+ messageKey,
+ setLinkModalActive,
+ displayURL,
+ onDismiss,
+ onConfirm,
+ inviteLinksContext,
+ ]);
}
type TextProps = React.ElementConfig<typeof Text>;
@@ -76,7 +93,7 @@
const onPressMessage = messagePressResponderContext?.onPressMessage;
- const onPressLink = useDisplayLinkPrompt(target, markdownContext, messageKey);
+ const onPressLink = useHandleLinkClick(target, markdownContext, messageKey);
return (
<Text
diff --git a/native/navigation/navigation-handler.react.js b/native/navigation/navigation-handler.react.js
--- a/native/navigation/navigation-handler.react.js
+++ b/native/navigation/navigation-handler.react.js
@@ -6,7 +6,6 @@
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
import { logInActionType, logOutActionType } from './action-types.js';
-import InviteLinkHandler from './invite-link-handler.react.js';
import ModalPruner from './modal-pruner.react.js';
import NavFromReduxHandler from './nav-from-redux-handler.react.js';
import { useIsAppLoggedIn } from './nav-selectors.js';
@@ -44,7 +43,6 @@
<ThreadScreenTracker />
<ModalPruner navContext={navContext} />
<PolicyAcknowledgmentHandler />
- <InviteLinkHandler />
{devTools}
</>
);
diff --git a/native/root.react.js b/native/root.react.js
--- a/native/root.react.js
+++ b/native/root.react.js
@@ -33,6 +33,7 @@
import { SQLiteDataHandler } from './data/sqlite-data-handler.js';
import ErrorBoundary from './error-boundary.react.js';
import InputStateContainer from './input/input-state-container.react.js';
+import { InviteLinksContextProvider } from './invite-links/invite-links-context-provider.react.js';
import LifecycleHandler from './lifecycle/lifecycle-handler.react.js';
import MarkdownContextProvider from './markdown/markdown-context-provider.react.js';
import { filesystemMediaCache } from './media/media-cache.js';
@@ -249,7 +250,9 @@
theme={theme}
ref={containerRef}
>
- <RootNavigator />
+ <InviteLinksContextProvider>
+ <RootNavigator />
+ </InviteLinksContextProvider>
<NavigationHandler />
</NavigationContainer>
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 12:30 PM (7 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2700001
Default Alt Text
D8637.diff (5 KB)
Attached To
Mode
D8637: [native] Handle invite links in chats
Attached
Detach File
Event Timeline
Log In to Comment