diff options
author | Jan-Olof Eriksson <jan-olof.eriksson@iki.fi> | 2024-03-04 18:11:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-04 18:11:00 +0200 |
commit | e724ab812346b4224b3efb2de0960f2cda88861b (patch) | |
tree | 9192c98b2b0b4be3388019b15b02a5d7df7fcce2 /src/lib/hooks | |
parent | 963a44ab872a1044d6997a8fcf7b2fc754ac618a (diff) | |
parent | b70c404d4b369d6fab0dfbafd6b31390ffd20014 (diff) | |
download | voidsky-e724ab812346b4224b3efb2de0960f2cda88861b.tar.zst |
Merge branch 'bluesky-social:main' into main
Diffstat (limited to 'src/lib/hooks')
-rw-r--r-- | src/lib/hooks/useIntentHandler.ts | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/lib/hooks/useIntentHandler.ts b/src/lib/hooks/useIntentHandler.ts index d1e2de31d..8741530b5 100644 --- a/src/lib/hooks/useIntentHandler.ts +++ b/src/lib/hooks/useIntentHandler.ts @@ -15,15 +15,20 @@ export function useIntentHandler() { React.useEffect(() => { const handleIncomingURL = (url: string) => { + // 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 + // of two cases when parsing the url. If we ensure there is a third slash, we can always ensure the first + // path parameter is in pathname rather than in hostname. + if (url.startsWith('bluesky://') && !url.startsWith('bluesky:///')) { + url = url.replace('bluesky://', 'bluesky:///') + } + const urlp = new URL(url) - const [_, intentTypeNative, intentTypeWeb] = urlp.pathname.split('/') + const [_, intent, intentType] = urlp.pathname.split('/') // On native, our links look like bluesky://intent/SomeIntent, so we have to check the hostname for the // intent check. On web, we have to check the first part of the path since we have an actual hostname - const intentType = isNative ? intentTypeNative : intentTypeWeb - const isIntent = isNative - ? urlp.hostname === 'intent' - : intentTypeNative === 'intent' + const isIntent = intent === 'intent' const params = urlp.searchParams if (!isIntent) return @@ -69,10 +74,7 @@ function useComposeIntent() { return false } // We also should just filter out cases that don't have all the info we need - if (!VALID_IMAGE_REGEX.test(part)) { - return false - } - return true + return VALID_IMAGE_REGEX.test(part) }) .map(part => { const [uri, width, height] = part.split('|') |