From 306f16263905eb8bca4463b735b5987aeb3cc5d1 Mon Sep 17 00:00:00 2001 From: Hailey Date: Fri, 12 Jul 2024 07:37:43 -0700 Subject: [PATCH] Make all referrer info sync (#4782) --- .../referrer/ExpoBlueskyReferrerModule.kt | 8 ++++---- .../src/Referrer/index.android.ts | 4 ++-- .../src/Referrer/index.ios.ts | 4 ++-- .../src/Referrer/index.ts | 2 +- .../src/Referrer/index.web.ts | 2 +- src/Navigation.tsx | 17 ++++++++--------- src/lib/hooks/useIntentHandler.ts | 17 ++++++++--------- 7 files changed, 26 insertions(+), 28 deletions(-) diff --git a/modules/expo-bluesky-swiss-army/android/src/main/java/expo/modules/blueskyswissarmy/referrer/ExpoBlueskyReferrerModule.kt b/modules/expo-bluesky-swiss-army/android/src/main/java/expo/modules/blueskyswissarmy/referrer/ExpoBlueskyReferrerModule.kt index bac55523..52b4daa3 100644 --- a/modules/expo-bluesky-swiss-army/android/src/main/java/expo/modules/blueskyswissarmy/referrer/ExpoBlueskyReferrerModule.kt +++ b/modules/expo-bluesky-swiss-army/android/src/main/java/expo/modules/blueskyswissarmy/referrer/ExpoBlueskyReferrerModule.kt @@ -23,7 +23,7 @@ class ExpoBlueskyReferrerModule : Module() { activityReferrer = appContext.currentActivity?.referrer } - AsyncFunction("getReferrerInfoAsync") { + Function("getReferrerInfo") { val intentReferrer = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { intent?.getParcelableExtra(Intent.EXTRA_REFERRER, Uri::class.java) @@ -40,7 +40,7 @@ class ExpoBlueskyReferrerModule : Module() { "hostname" to intentReferrer.host, ) intent = null - return@AsyncFunction res + return@Function res } // In all other cases, we'll just record the app that sent the intent. @@ -52,10 +52,10 @@ class ExpoBlueskyReferrerModule : Module() { "hostname" to (activityReferrer?.host ?: ""), ) activityReferrer = null - return@AsyncFunction res + return@Function res } - return@AsyncFunction null + return@Function null } AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise -> diff --git a/modules/expo-bluesky-swiss-army/src/Referrer/index.android.ts b/modules/expo-bluesky-swiss-army/src/Referrer/index.android.ts index ec2bcb57..795c6146 100644 --- a/modules/expo-bluesky-swiss-army/src/Referrer/index.android.ts +++ b/modules/expo-bluesky-swiss-army/src/Referrer/index.android.ts @@ -8,6 +8,6 @@ export function getGooglePlayReferrerInfoAsync(): Promise { - return NativeModule.getReferrerInfoAsync() +export function getReferrerInfo(): Promise { + return NativeModule.getReferrerInfo() } diff --git a/modules/expo-bluesky-swiss-army/src/Referrer/index.ios.ts b/modules/expo-bluesky-swiss-army/src/Referrer/index.ios.ts index 2bf1497a..e76893d3 100644 --- a/modules/expo-bluesky-swiss-army/src/Referrer/index.ios.ts +++ b/modules/expo-bluesky-swiss-army/src/Referrer/index.ios.ts @@ -6,7 +6,7 @@ export function getGooglePlayReferrerInfoAsync(): Promise { +export function getReferrerInfo(): ReferrerInfo | null { const referrer = SharedPrefs.getString('referrer') if (referrer) { SharedPrefs.removeValue('referrer') @@ -19,7 +19,7 @@ export function getReferrerInfoAsync(): Promise { } catch (e) { return { referrer, - hostname: undefined, + hostname: referrer, } } } diff --git a/modules/expo-bluesky-swiss-army/src/Referrer/index.ts b/modules/expo-bluesky-swiss-army/src/Referrer/index.ts index a60f7b6d..ac594402 100644 --- a/modules/expo-bluesky-swiss-army/src/Referrer/index.ts +++ b/modules/expo-bluesky-swiss-army/src/Referrer/index.ts @@ -5,6 +5,6 @@ export function getGooglePlayReferrerInfoAsync(): Promise { +export function getReferrerInfo(): ReferrerInfo | null { throw new NotImplementedError() } diff --git a/modules/expo-bluesky-swiss-army/src/Referrer/index.web.ts b/modules/expo-bluesky-swiss-army/src/Referrer/index.web.ts index c092a67e..cfd42642 100644 --- a/modules/expo-bluesky-swiss-army/src/Referrer/index.web.ts +++ b/modules/expo-bluesky-swiss-army/src/Referrer/index.web.ts @@ -7,7 +7,7 @@ export function getGooglePlayReferrerInfoAsync(): Promise { +export function getReferrerInfo(): ReferrerInfo | null { if ( Platform.OS === 'web' && // for ssr diff --git a/src/Navigation.tsx b/src/Navigation.tsx index 8c815a3f..9e9b4944 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -771,15 +771,14 @@ function logModuleInitTime() { }) if (isWeb) { - Referrer.getReferrerInfoAsync().then(info => { - if (info && info.hostname !== 'bsky.app') { - logEvent('deepLink:referrerReceived', { - to: window.location.href, - referrer: info?.referrer, - hostname: info?.hostname, - }) - } - }) + const referrerInfo = Referrer.getReferrerInfo() + if (referrerInfo && referrerInfo.hostname !== 'bsky.app') { + logEvent('deepLink:referrerReceived', { + to: window.location.href, + referrer: referrerInfo?.referrer, + hostname: referrerInfo?.hostname, + }) + } } if (__DEV__) { diff --git a/src/lib/hooks/useIntentHandler.ts b/src/lib/hooks/useIntentHandler.ts index 3235e1a6..460df375 100644 --- a/src/lib/hooks/useIntentHandler.ts +++ b/src/lib/hooks/useIntentHandler.ts @@ -18,15 +18,14 @@ export function useIntentHandler() { React.useEffect(() => { const handleIncomingURL = (url: string) => { - Referrer.getReferrerInfoAsync().then(info => { - if (info && info.hostname !== 'bsky.app') { - logEvent('deepLink:referrerReceived', { - to: url, - referrer: info?.referrer, - hostname: info?.hostname, - }) - } - }) + const referrerInfo = Referrer.getReferrerInfo() + if (referrerInfo && referrerInfo.hostname !== 'bsky.app') { + logEvent('deepLink:referrerReceived', { + to: url, + referrer: referrerInfo?.referrer, + hostname: referrerInfo?.hostname, + }) + } // We want to be able to support bluesky:// deeplinks. It's unnatural for someone to use a deeplink with three // slashes, like bluesky:///intent/follow. However, supporting just two slashes causes us to have to take care