Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tweak link handling (#7857)

authored by

Hailey and committed by
GitHub
a2b71e3a a3d36393

+43 -2
+13 -1
src/components/Link.tsx
··· 69 69 * Native-only attribute. If true, will open the share sheet on long press. 70 70 */ 71 71 shareOnLongPress?: boolean 72 + 73 + /** 74 + * Whether the link should be opened through the redirect proxy. 75 + */ 76 + shouldProxy?: boolean 72 77 } 73 78 74 79 export function useLink({ ··· 80 85 onLongPress: outerOnLongPress, 81 86 shareOnLongPress, 82 87 overridePresentation, 88 + shouldProxy, 83 89 }: BaseLinkProps & { 84 90 displayText: string 85 91 overridePresentation?: boolean 92 + shouldProxy?: boolean 86 93 }) { 87 94 const navigation = useNavigationDeduped() 88 95 const {href} = useLinkProps<AllNavigatorParams>({ ··· 118 125 }) 119 126 } else { 120 127 if (isExternal) { 121 - openLink(href, overridePresentation) 128 + openLink(href, overridePresentation, shouldProxy) 122 129 } else { 123 130 const shouldOpenInNewTab = shouldClickOpenNewTab(e) 124 131 ··· 161 168 action, 162 169 navigation, 163 170 overridePresentation, 171 + shouldProxy, 164 172 ], 165 173 ) 166 174 ··· 219 227 onPress: outerOnPress, 220 228 onLongPress: outerOnLongPress, 221 229 download, 230 + shouldProxy, 222 231 ...rest 223 232 }: LinkProps) { 224 233 const {href, isExternal, onPress, onLongPress} = useLink({ ··· 227 236 action, 228 237 onPress: outerOnPress, 229 238 onLongPress: outerOnLongPress, 239 + shouldProxy: shouldProxy, 230 240 }) 231 241 232 242 return ( ··· 279 289 shareOnLongPress, 280 290 disableUnderline, 281 291 overridePresentation, 292 + shouldProxy, 282 293 ...rest 283 294 }: InlineLinkProps) { 284 295 const t = useTheme() ··· 292 303 onLongPress: outerOnLongPress, 293 304 shareOnLongPress, 294 305 overridePresentation, 306 + shouldProxy: shouldProxy, 295 307 }) 296 308 const { 297 309 state: hovered,
+4
src/components/RichText.tsx
··· 23 23 onLinkPress?: LinkProps['onPress'] 24 24 interactiveStyle?: TextStyle 25 25 emojiMultiplier?: number 26 + shouldProxyLinks?: boolean 26 27 } 27 28 28 29 export function RichText({ ··· 39 40 emojiMultiplier = 1.85, 40 41 onLayout, 41 42 onTextLayout, 43 + shouldProxyLinks, 42 44 }: RichTextProps) { 43 45 const richText = React.useMemo( 44 46 () => ··· 110 112 style={interactiveStyles} 111 113 // @ts-ignore TODO 112 114 dataSet={WORD_WRAP} 115 + shouldProxy={shouldProxyLinks} 113 116 onPress={onLinkPress}> 114 117 {segment.text} 115 118 </InlineLinkText> ··· 128 131 // @ts-ignore TODO 129 132 dataSet={WORD_WRAP} 130 133 shareOnLongPress 134 + shouldProxy={shouldProxyLinks} 131 135 onPress={onLinkPress} 132 136 emoji> 133 137 {toShortUrl(segment.text)}
+6 -1
src/lib/hooks/useOpenLink.ts
··· 5 5 import {logEvent} from '#/lib/statsig/statsig' 6 6 import { 7 7 createBskyAppAbsoluteUrl, 8 + createProxiedUrl, 8 9 isBskyAppUrl, 9 10 isBskyRSSUrl, 10 11 isRelativeUrl, ··· 23 24 const sheetWrapper = useSheetWrapper() 24 25 25 26 const openLink = useCallback( 26 - async (url: string, override?: boolean) => { 27 + async (url: string, override?: boolean, shouldProxy?: boolean) => { 27 28 if (isBskyRSSUrl(url) && isRelativeUrl(url)) { 28 29 url = createBskyAppAbsoluteUrl(url) 29 30 } ··· 33 34 domain: toNiceDomain(url), 34 35 url, 35 36 }) 37 + 38 + if (shouldProxy) { 39 + url = createProxiedUrl(url) 40 + } 36 41 } 37 42 38 43 if (isNative && !url.startsWith('mailto:')) {
+15
src/lib/strings/url-helpers.ts
··· 320 320 return `${BSKY_APP_HOST.replace(/\/$/, '')}/${sanitizedPath}` 321 321 } 322 322 323 + export function createProxiedUrl(url: string): string { 324 + let u 325 + try { 326 + u = URL.parse(url) 327 + } catch { 328 + return url 329 + } 330 + 331 + if (u?.protocol !== 'http:' && u?.protocol !== 'https:') { 332 + return url 333 + } 334 + 335 + return `https://go.bsky.app/redirect?u=${url}` 336 + } 337 + 323 338 export function isShortLink(url: string): boolean { 324 339 return url.startsWith('https://go.bsky.app/') 325 340 }
+2
src/view/com/post-thread/PostThreadItem.tsx
··· 375 375 value={richText} 376 376 style={[a.flex_1, a.text_xl]} 377 377 authorHandle={post.author.handle} 378 + shouldProxyLinks={true} 378 379 /> 379 380 ) : undefined} 380 381 {post.embed && ( ··· 590 591 style={[a.flex_1, a.text_md]} 591 592 numberOfLines={limitLines ? MAX_POST_LINES : undefined} 592 593 authorHandle={post.author.handle} 594 + shouldProxyLinks={true} 593 595 /> 594 596 </View> 595 597 ) : undefined}
+1
src/view/com/post/Post.tsx
··· 234 234 numberOfLines={limitLines ? MAX_POST_LINES : undefined} 235 235 style={[a.flex_1, a.text_md]} 236 236 authorHandle={post.author.handle} 237 + shouldProxyLinks={true} 237 238 /> 238 239 </View> 239 240 ) : undefined}
+1
src/view/com/posts/PostFeedItem.tsx
··· 506 506 numberOfLines={limitLines ? MAX_POST_LINES : undefined} 507 507 style={[a.flex_1, a.text_md]} 508 508 authorHandle={postAuthor.handle} 509 + shouldProxyLinks={true} 509 510 /> 510 511 </View> 511 512 ) : undefined}
+1
src/view/com/util/post-embeds/ExternalLinkEmbed.tsx
··· 70 70 <Link 71 71 label={link.title || _(msg`Open link to ${niceUrl}`)} 72 72 to={link.uri} 73 + shouldProxy={true} 73 74 onPress={onOpen} 74 75 onLongPress={onShareExternal}> 75 76 {({hovered}) => (