1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
This commit is contained in:
xmflsct
2023-03-12 18:09:33 +01:00
parent 0db7f0c40a
commit 173d4248d8
5 changed files with 45 additions and 29 deletions

View File

@ -0,0 +1,41 @@
import openLink from '@components/openLink'
import navigationRef from '@utils/navigation/navigationRef'
import { getReadableAccounts, setAccount } from '@utils/storage/actions'
import * as Linking from 'expo-linking'
import { useEffect } from 'react'
// /compose OR /compose/@username@example.com
export const useLinking = () => {
const parseLink = async (link: string) => {
const parsed = Linking.parse(link)
switch (parsed.scheme) {
case 'tooot':
if (parsed.hostname === 'compose') {
if (parsed.path?.length) {
const accounts = getReadableAccounts()
const foundNotActiveAccount = accounts.find(
account => account.acct === parsed.path && !account.active
)
if (foundNotActiveAccount) {
await setAccount(foundNotActiveAccount.key)
}
}
navigationRef.navigate('Screen-Compose')
}
break
case 'https':
case 'http':
await openLink(link)
break
}
}
useEffect(() => {
Linking.getInitialURL().then(parseLink)
const listener = Linking.addEventListener('url', ({ url }) => parseLink(url))
return () => listener.remove()
}, [])
}