about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-11-23 10:51:20 -0600
committerPaul Frazee <pfrazee@gmail.com>2022-11-23 10:51:20 -0600
commitf41ba844b3ebfb7fde3cb0254b7fa585895ab323 (patch)
treeedd676c8de61aac97cb967633c629556355102dc /src
parentb4a8da4c27081fdc6acfb924b263b93fed4cd6c2 (diff)
downloadvoidsky-f41ba844b3ebfb7fde3cb0254b7fa585895ab323.tar.zst
Handle bsky.app links natively
Diffstat (limited to 'src')
-rw-r--r--src/lib/strings.ts14
-rw-r--r--src/view/com/util/Link.tsx5
2 files changed, 16 insertions, 3 deletions
diff --git a/src/lib/strings.ts b/src/lib/strings.ts
index eaccb63a0..6457e4b90 100644
--- a/src/lib/strings.ts
+++ b/src/lib/strings.ts
@@ -198,7 +198,7 @@ export function toShortUrl(url: string): string {
   }
 }
 
-export function toShareUrl(url: string) {
+export function toShareUrl(url: string): string {
   if (!url.startsWith('https')) {
     const urlp = new URL('https://bsky.app')
     urlp.pathname = url
@@ -206,3 +206,15 @@ export function toShareUrl(url: string) {
   }
   return url
 }
+
+export function convertBskyAppUrlIfNeeded(url: string): string {
+  if (url.startsWith('https://bsky.app/')) {
+    try {
+      const urlp = new URL(url)
+      return urlp.pathname
+    } catch (e) {
+      console.log('Unexpected error in convertBskyAppUrlIfNeeded()', e)
+    }
+  }
+  return url
+}
diff --git a/src/view/com/util/Link.tsx b/src/view/com/util/Link.tsx
index 8f94115e1..70ba0df7a 100644
--- a/src/view/com/util/Link.tsx
+++ b/src/view/com/util/Link.tsx
@@ -8,8 +8,8 @@ import {
   TextStyle,
   ViewStyle,
 } from 'react-native'
-import {useStores} from '../../../state'
-import {RootStoreModel} from '../../../state'
+import {useStores, RootStoreModel} from '../../../state'
+import {convertBskyAppUrlIfNeeded} from '../../../lib/strings'
 
 export const Link = observer(function Link({
   style,
@@ -66,6 +66,7 @@ export const TextLink = observer(function Link({
 })
 
 function handleLink(store: RootStoreModel, href: string, longPress: boolean) {
+  href = convertBskyAppUrlIfNeeded(href)
   if (href.startsWith('http')) {
     Linking.openURL(href)
   } else if (longPress) {