add
This commit is contained in:
@@ -69,6 +69,11 @@ type BaseLinkProps = Pick<
|
|||||||
* Native-only attribute. If true, will open the share sheet on long press.
|
* Native-only attribute. If true, will open the share sheet on long press.
|
||||||
*/
|
*/
|
||||||
shareOnLongPress?: boolean
|
shareOnLongPress?: boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the link should be opened through the redirect proxy.
|
||||||
|
*/
|
||||||
|
shouldProxy?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useLink({
|
export function useLink({
|
||||||
@@ -80,9 +85,11 @@ export function useLink({
|
|||||||
onLongPress: outerOnLongPress,
|
onLongPress: outerOnLongPress,
|
||||||
shareOnLongPress,
|
shareOnLongPress,
|
||||||
overridePresentation,
|
overridePresentation,
|
||||||
|
shouldProxy,
|
||||||
}: BaseLinkProps & {
|
}: BaseLinkProps & {
|
||||||
displayText: string
|
displayText: string
|
||||||
overridePresentation?: boolean
|
overridePresentation?: boolean
|
||||||
|
shouldProxy?: boolean
|
||||||
}) {
|
}) {
|
||||||
const navigation = useNavigationDeduped()
|
const navigation = useNavigationDeduped()
|
||||||
const {href} = useLinkProps<AllNavigatorParams>({
|
const {href} = useLinkProps<AllNavigatorParams>({
|
||||||
@@ -118,7 +125,7 @@ export function useLink({
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
openLink(href, overridePresentation)
|
openLink(href, overridePresentation, shouldProxy)
|
||||||
} else {
|
} else {
|
||||||
const shouldOpenInNewTab = shouldClickOpenNewTab(e)
|
const shouldOpenInNewTab = shouldClickOpenNewTab(e)
|
||||||
|
|
||||||
@@ -161,6 +168,7 @@ export function useLink({
|
|||||||
action,
|
action,
|
||||||
navigation,
|
navigation,
|
||||||
overridePresentation,
|
overridePresentation,
|
||||||
|
shouldProxy,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export type RichTextProps = TextStyleProp &
|
|||||||
onLinkPress?: LinkProps['onPress']
|
onLinkPress?: LinkProps['onPress']
|
||||||
interactiveStyle?: TextStyle
|
interactiveStyle?: TextStyle
|
||||||
emojiMultiplier?: number
|
emojiMultiplier?: number
|
||||||
|
shouldProxyLinks?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RichText({
|
export function RichText({
|
||||||
@@ -39,6 +40,7 @@ export function RichText({
|
|||||||
emojiMultiplier = 1.85,
|
emojiMultiplier = 1.85,
|
||||||
onLayout,
|
onLayout,
|
||||||
onTextLayout,
|
onTextLayout,
|
||||||
|
shouldProxyLinks,
|
||||||
}: RichTextProps) {
|
}: RichTextProps) {
|
||||||
const richText = React.useMemo(
|
const richText = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -110,6 +112,7 @@ export function RichText({
|
|||||||
style={interactiveStyles}
|
style={interactiveStyles}
|
||||||
// @ts-ignore TODO
|
// @ts-ignore TODO
|
||||||
dataSet={WORD_WRAP}
|
dataSet={WORD_WRAP}
|
||||||
|
shouldProxy={shouldProxyLinks}
|
||||||
onPress={onLinkPress}>
|
onPress={onLinkPress}>
|
||||||
{segment.text}
|
{segment.text}
|
||||||
</InlineLinkText>
|
</InlineLinkText>
|
||||||
@@ -128,6 +131,7 @@ export function RichText({
|
|||||||
// @ts-ignore TODO
|
// @ts-ignore TODO
|
||||||
dataSet={WORD_WRAP}
|
dataSet={WORD_WRAP}
|
||||||
shareOnLongPress
|
shareOnLongPress
|
||||||
|
shouldProxy={shouldProxyLinks}
|
||||||
onPress={onLinkPress}
|
onPress={onLinkPress}
|
||||||
emoji>
|
emoji>
|
||||||
{toShortUrl(segment.text)}
|
{toShortUrl(segment.text)}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import * as WebBrowser from 'expo-web-browser'
|
|||||||
import {logEvent} from '#/lib/statsig/statsig'
|
import {logEvent} from '#/lib/statsig/statsig'
|
||||||
import {
|
import {
|
||||||
createBskyAppAbsoluteUrl,
|
createBskyAppAbsoluteUrl,
|
||||||
|
createProxiedUrl,
|
||||||
isBskyAppUrl,
|
isBskyAppUrl,
|
||||||
isBskyRSSUrl,
|
isBskyRSSUrl,
|
||||||
isRelativeUrl,
|
isRelativeUrl,
|
||||||
@@ -23,7 +24,7 @@ export function useOpenLink() {
|
|||||||
const sheetWrapper = useSheetWrapper()
|
const sheetWrapper = useSheetWrapper()
|
||||||
|
|
||||||
const openLink = useCallback(
|
const openLink = useCallback(
|
||||||
async (url: string, override?: boolean) => {
|
async (url: string, override?: boolean, shouldProxy?: boolean) => {
|
||||||
if (isBskyRSSUrl(url) && isRelativeUrl(url)) {
|
if (isBskyRSSUrl(url) && isRelativeUrl(url)) {
|
||||||
url = createBskyAppAbsoluteUrl(url)
|
url = createBskyAppAbsoluteUrl(url)
|
||||||
}
|
}
|
||||||
@@ -33,6 +34,10 @@ export function useOpenLink() {
|
|||||||
domain: toNiceDomain(url),
|
domain: toNiceDomain(url),
|
||||||
url,
|
url,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (shouldProxy) {
|
||||||
|
url = createProxiedUrl(url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNative && !url.startsWith('mailto:')) {
|
if (isNative && !url.startsWith('mailto:')) {
|
||||||
|
|||||||
@@ -320,6 +320,21 @@ export function createBskyAppAbsoluteUrl(path: string): string {
|
|||||||
return `${BSKY_APP_HOST.replace(/\/$/, '')}/${sanitizedPath}`
|
return `${BSKY_APP_HOST.replace(/\/$/, '')}/${sanitizedPath}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createProxiedUrl(url: string): string {
|
||||||
|
let u
|
||||||
|
try {
|
||||||
|
u = URL.parse(url)
|
||||||
|
} catch {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
if (u?.protocol !== 'http:' && u?.protocol !== 'https:') {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
return `https://go.bsky.app/redirect?u=${url}`
|
||||||
|
}
|
||||||
|
|
||||||
export function isShortLink(url: string): boolean {
|
export function isShortLink(url: string): boolean {
|
||||||
return url.startsWith('https://go.bsky.app/')
|
return url.startsWith('https://go.bsky.app/')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,6 +234,7 @@ function PostInner({
|
|||||||
numberOfLines={limitLines ? MAX_POST_LINES : undefined}
|
numberOfLines={limitLines ? MAX_POST_LINES : undefined}
|
||||||
style={[a.flex_1, a.text_md]}
|
style={[a.flex_1, a.text_md]}
|
||||||
authorHandle={post.author.handle}
|
authorHandle={post.author.handle}
|
||||||
|
shouldProxyLinks
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export const ExternalLinkEmbed = ({
|
|||||||
<Link
|
<Link
|
||||||
label={link.title || _(msg`Open link to ${niceUrl}`)}
|
label={link.title || _(msg`Open link to ${niceUrl}`)}
|
||||||
to={link.uri}
|
to={link.uri}
|
||||||
|
shouldProxy={true}
|
||||||
onPress={onOpen}
|
onPress={onOpen}
|
||||||
onLongPress={onShareExternal}>
|
onLongPress={onShareExternal}>
|
||||||
{({hovered}) => (
|
{({hovered}) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user