about summary refs log tree commit diff
path: root/src/Navigation.tsx
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2025-07-17 21:18:16 +0300
committerGitHub <noreply@github.com>2025-07-17 21:18:16 +0300
commit2c0c9bf803f995508e35d4dba954924c53beec87 (patch)
tree4907bc4df9b082b047e400929455a81b21d887f2 /src/Navigation.tsx
parent2e16ef4384e49c951dc8c53c0a74935485985f68 (diff)
downloadvoidsky-2c0c9bf803f995508e35d4dba954924c53beec87.tar.zst
avoid handling notifs if deep link (#8657)
Diffstat (limited to 'src/Navigation.tsx')
-rw-r--r--src/Navigation.tsx42
1 files changed, 8 insertions, 34 deletions
diff --git a/src/Navigation.tsx b/src/Navigation.tsx
index e71148a2c..a7e495f7c 100644
--- a/src/Navigation.tsx
+++ b/src/Navigation.tsx
@@ -1,4 +1,5 @@
 import {useCallback, useRef} from 'react'
+import {Linking} from 'react-native'
 import * as Notifications from 'expo-notifications'
 import {i18n, type MessageDescriptor} from '@lingui/core'
 import {msg} from '@lingui/macro'
@@ -884,6 +885,13 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) {
   async function handlePushNotificationEntry() {
     if (!isNative) return
 
+    // deep links take precedence - on android,
+    // getLastNotificationResponseAsync returns a "notification"
+    // that is actually a deep link. avoid handling it twice -sfn
+    if (await Linking.getInitialURL()) {
+      return
+    }
+
     /**
      * The notification that caused the app to open, if applicable
      */
@@ -1041,39 +1049,6 @@ function reset(): Promise<void> {
   }
 }
 
-function handleLink(url: string) {
-  let path
-  if (url.startsWith('/')) {
-    path = url
-  } else if (url.startsWith('http')) {
-    try {
-      path = new URL(url).pathname
-    } catch (e) {
-      console.error('Invalid url', url, e)
-      return
-    }
-  } else {
-    console.error('Invalid url', url)
-    return
-  }
-
-  const [name, params] = router.matchPath(path)
-  if (isNative) {
-    if (name === 'Search') {
-      resetToTab('SearchTab')
-    } else if (name === 'Notifications') {
-      resetToTab('NotificationsTab')
-    } else {
-      resetToTab('HomeTab')
-      // @ts-ignore matchPath doesnt give us type-checked output -prf
-      navigate(name, params)
-    }
-  } else {
-    // @ts-ignore matchPath doesnt give us type-checked output -prf
-    navigate(name, params)
-  }
-}
-
 let didInit = false
 function logModuleInitTime() {
   if (didInit) {
@@ -1114,7 +1089,6 @@ function logModuleInitTime() {
 
 export {
   FlatNavigator,
-  handleLink,
   navigate,
   reset,
   resetToTab,