mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Fixed #446
This commit is contained in:
@ -1,24 +1,12 @@
|
||||
import apiInstance from '@api/instance'
|
||||
import navigationRef from '@helpers/navigationRef'
|
||||
import { matchAccount, matchStatus } from '@helpers/urlMatcher'
|
||||
import { store } from '@root/store'
|
||||
import { SearchResult } from '@utils/queryHooks/search'
|
||||
import { getInstanceUrl } from '@utils/slices/instancesSlice'
|
||||
import { getSettingsBrowser } from '@utils/slices/settingsSlice'
|
||||
import * as Linking from 'expo-linking'
|
||||
import * as WebBrowser from 'expo-web-browser'
|
||||
|
||||
// https://social.xmflsct.com/web/statuses/105590085754428765 <- default
|
||||
// https://social.xmflsct.com/@tooot/105590085754428765 <- pretty
|
||||
const matcherStatus = new RegExp(
|
||||
/http[s]?:\/\/(.*)\/(web\/statuses|@.*)\/([0-9]*)/
|
||||
)
|
||||
|
||||
// https://social.xmflsct.com/web/accounts/14195 <- default
|
||||
// https://social.xmflsct.com/@tooot <- pretty
|
||||
const matcherAccount = new RegExp(
|
||||
/http[s]?:\/\/(.*)\/(web\/accounts\/([0-9]*)|@.*)/
|
||||
)
|
||||
|
||||
export let loadingLink = false
|
||||
|
||||
const openLink = async (url: string, navigation?: any) => {
|
||||
@ -26,10 +14,7 @@ const openLink = async (url: string, navigation?: any) => {
|
||||
return
|
||||
}
|
||||
|
||||
const handleNavigation = (
|
||||
page: 'Tab-Shared-Toot' | 'Tab-Shared-Account',
|
||||
options: {}
|
||||
) => {
|
||||
const handleNavigation = (page: 'Tab-Shared-Toot' | 'Tab-Shared-Account', options: {}) => {
|
||||
if (navigation) {
|
||||
// @ts-ignore
|
||||
navigation.push(page, options)
|
||||
@ -40,14 +25,10 @@ const openLink = async (url: string, navigation?: any) => {
|
||||
}
|
||||
|
||||
// If a tooot can be found
|
||||
const matchedStatus = url.match(matcherStatus)
|
||||
if (matchedStatus) {
|
||||
// If the link in current instance
|
||||
const instanceUrl = getInstanceUrl(store.getState())
|
||||
if (matchedStatus[1] === instanceUrl) {
|
||||
handleNavigation('Tab-Shared-Toot', {
|
||||
toot: { id: matchedStatus[3] }
|
||||
})
|
||||
const isStatus = matchStatus(url)
|
||||
if (isStatus) {
|
||||
if (isStatus.sameInstance) {
|
||||
handleNavigation('Tab-Shared-Toot', { toot: { id: isStatus.id } })
|
||||
return
|
||||
}
|
||||
|
||||
@ -71,15 +52,11 @@ const openLink = async (url: string, navigation?: any) => {
|
||||
}
|
||||
|
||||
// If an account can be found
|
||||
const matchedAccount = url.match(matcherAccount)
|
||||
if (matchedAccount) {
|
||||
// If the link in current instance
|
||||
const instanceUrl = getInstanceUrl(store.getState())
|
||||
if (matchedAccount[1] === instanceUrl) {
|
||||
if (matchedAccount[3] && matchedAccount[3].match(/[0-9]*/)) {
|
||||
handleNavigation('Tab-Shared-Account', {
|
||||
account: { id: matchedAccount[3] }
|
||||
})
|
||||
const isAccount = matchAccount(url)
|
||||
if (isAccount) {
|
||||
if (isAccount.sameInstance) {
|
||||
if (isAccount.style === 'default' && isAccount.id) {
|
||||
handleNavigation('Tab-Shared-Account', { account: isAccount })
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -91,7 +68,12 @@ const openLink = async (url: string, navigation?: any) => {
|
||||
version: 'v2',
|
||||
method: 'get',
|
||||
url: 'search',
|
||||
params: { type: 'accounts', q: url, limit: 1, resolve: true }
|
||||
params: {
|
||||
type: 'accounts',
|
||||
q: isAccount.sameInstance && isAccount.style === 'pretty' ? isAccount.username : url,
|
||||
limit: 1,
|
||||
resolve: true
|
||||
}
|
||||
})
|
||||
} catch {}
|
||||
if (response && response.body && response.body.accounts.length) {
|
||||
|
Reference in New Issue
Block a user