mirror of https://github.com/tooot-app/app
Fix link matching crashes
This commit is contained in:
parent
9f6e7738bf
commit
1dd64c4e19
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "tooot",
|
"name": "tooot",
|
||||||
"version": "4.8.7",
|
"version": "4.8.8",
|
||||||
"description": "tooot for Mastodon",
|
"description": "tooot for Mastodon",
|
||||||
"author": "xmflsct <me@xmflsct.com>",
|
"author": "xmflsct <me@xmflsct.com>",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
|
|
|
@ -46,17 +46,9 @@ const openLink = async (url: string, navigation?: any) => {
|
||||||
|
|
||||||
// If an account can be found
|
// If an account can be found
|
||||||
if (match?.account) {
|
if (match?.account) {
|
||||||
if (!match.account._remote && match.account.id) {
|
|
||||||
handleNavigation('Tab-Shared-Account', { account: match.account.id })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let response: Mastodon.Account | undefined = undefined
|
let response: Mastodon.Account | undefined = undefined
|
||||||
|
|
||||||
const queryKey: QueryKeyAccount = [
|
const queryKey: QueryKeyAccount = ['Account', { url: url, _remote: match.account._remote }]
|
||||||
'Account',
|
|
||||||
{ id: match.account.id, url: url, _remote: match.account._remote }
|
|
||||||
]
|
|
||||||
const cache = queryClient.getQueryData<Mastodon.Status>(queryKey)
|
const cache = queryClient.getQueryData<Mastodon.Status>(queryKey)
|
||||||
|
|
||||||
if (cache) {
|
if (cache) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ export const urlMatcher = (
|
||||||
):
|
):
|
||||||
| {
|
| {
|
||||||
domain: string
|
domain: string
|
||||||
account?: Partial<Pick<Mastodon.Account, 'id' | 'acct' | '_remote'>>
|
account?: Partial<Pick<Mastodon.Account, 'acct' | '_remote'>>
|
||||||
status?: Partial<Pick<Mastodon.Status, 'id' | '_remote'>>
|
status?: Partial<Pick<Mastodon.Status, 'id' | '_remote'>>
|
||||||
}
|
}
|
||||||
| undefined => {
|
| undefined => {
|
||||||
|
@ -24,13 +24,18 @@ export const urlMatcher = (
|
||||||
const _remote = parsed.hostname !== getAccountStorage.string('auth.domain')
|
const _remote = parsed.hostname !== getAccountStorage.string('auth.domain')
|
||||||
|
|
||||||
let statusId: string | undefined
|
let statusId: string | undefined
|
||||||
let accountId: string | undefined
|
|
||||||
let accountAcct: string | undefined
|
let accountAcct: string | undefined
|
||||||
|
|
||||||
const segments = parsed.pathname.split('/')
|
const segments = parsed.pathname.split('/')
|
||||||
const last = segments[segments.length - 1]
|
const last = segments[segments.length - 1]
|
||||||
const length = segments.length // there is a starting slash
|
const length = segments.length // there is a starting slash
|
||||||
|
|
||||||
|
const testAndAssignStatusId = (id: string) => {
|
||||||
|
if (!!parseInt(id)) {
|
||||||
|
statusId = id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (last?.startsWith('@')) {
|
switch (last?.startsWith('@')) {
|
||||||
case true:
|
case true:
|
||||||
if (length === 2 || (length === 3 && segments[length - 2] === 'web')) {
|
if (length === 2 || (length === 3 && segments[length - 2] === 'web')) {
|
||||||
|
@ -45,14 +50,14 @@ export const urlMatcher = (
|
||||||
if (nextToLast === 'statuses') {
|
if (nextToLast === 'statuses') {
|
||||||
if (length === 4 && segments[length - 3] === 'web') {
|
if (length === 4 && segments[length - 3] === 'web') {
|
||||||
// https://social.xmflsct.com/web/statuses/105590085754428765 <- old
|
// https://social.xmflsct.com/web/statuses/105590085754428765 <- old
|
||||||
statusId = last
|
testAndAssignStatusId(last)
|
||||||
} else if (
|
} else if (
|
||||||
length === 5 &&
|
length === 5 &&
|
||||||
segments[length - 2] === 'statuses' &&
|
segments[length - 2] === 'statuses' &&
|
||||||
segments[length - 4] === 'users'
|
segments[length - 4] === 'users'
|
||||||
) {
|
) {
|
||||||
// https://social.xmflsct.com/users/tooot/statuses/105590085754428765 <- default Mastodon
|
// https://social.xmflsct.com/users/tooot/statuses/105590085754428765 <- default Mastodon
|
||||||
statusId = last
|
testAndAssignStatusId(last)
|
||||||
// accountAcct = `@${segments[length - 3]}@${domain}`
|
// accountAcct = `@${segments[length - 3]}@${domain}`
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -61,7 +66,7 @@ export const urlMatcher = (
|
||||||
) {
|
) {
|
||||||
// https://social.xmflsct.com/web/@tooot/105590085754428765 <- pretty Mastodon v3.5 and below
|
// https://social.xmflsct.com/web/@tooot/105590085754428765 <- pretty Mastodon v3.5 and below
|
||||||
// https://social.xmflsct.com/@tooot/105590085754428765 <- pretty Mastodon v4.0 and above
|
// https://social.xmflsct.com/@tooot/105590085754428765 <- pretty Mastodon v4.0 and above
|
||||||
statusId = last
|
testAndAssignStatusId(last)
|
||||||
// accountAcct = `${nextToLast}@${domain}`
|
// accountAcct = `${nextToLast}@${domain}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +75,7 @@ export const urlMatcher = (
|
||||||
|
|
||||||
return {
|
return {
|
||||||
domain,
|
domain,
|
||||||
...((accountId || accountAcct) && { account: { id: accountId, acct: accountAcct, _remote } }),
|
...(accountAcct && { account: { acct: accountAcct, _remote } }),
|
||||||
...(statusId && { status: { id: statusId, _remote } })
|
...(statusId && { status: { id: statusId, _remote } })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ const accountQueryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyA
|
||||||
const match = urlMatcher(key.url)
|
const match = urlMatcher(key.url)
|
||||||
|
|
||||||
const domain = match?.domain
|
const domain = match?.domain
|
||||||
const id = key.id || match?.account?.id
|
const id = key.id
|
||||||
const acct = key.acct || key.username || match?.account?.acct
|
const acct = key.acct || key.username || match?.account?.acct
|
||||||
|
|
||||||
if (!key._local && domain) {
|
if (!key._local && domain) {
|
||||||
|
|
Loading…
Reference in New Issue