Fix link matching crashes

This commit is contained in:
xmflsct 2023-02-06 14:00:40 +01:00
parent 9f6e7738bf
commit 1dd64c4e19
4 changed files with 14 additions and 17 deletions

View File

@ -1,6 +1,6 @@
{
"name": "tooot",
"version": "4.8.7",
"version": "4.8.8",
"description": "tooot for Mastodon",
"author": "xmflsct <me@xmflsct.com>",
"license": "GPL-3.0-or-later",

View File

@ -46,17 +46,9 @@ const openLink = async (url: string, navigation?: any) => {
// If an account can be found
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
const queryKey: QueryKeyAccount = [
'Account',
{ id: match.account.id, url: url, _remote: match.account._remote }
]
const queryKey: QueryKeyAccount = ['Account', { url: url, _remote: match.account._remote }]
const cache = queryClient.getQueryData<Mastodon.Status>(queryKey)
if (cache) {

View File

@ -9,7 +9,7 @@ export const urlMatcher = (
):
| {
domain: string
account?: Partial<Pick<Mastodon.Account, 'id' | 'acct' | '_remote'>>
account?: Partial<Pick<Mastodon.Account, 'acct' | '_remote'>>
status?: Partial<Pick<Mastodon.Status, 'id' | '_remote'>>
}
| undefined => {
@ -24,13 +24,18 @@ export const urlMatcher = (
const _remote = parsed.hostname !== getAccountStorage.string('auth.domain')
let statusId: string | undefined
let accountId: string | undefined
let accountAcct: string | undefined
const segments = parsed.pathname.split('/')
const last = segments[segments.length - 1]
const length = segments.length // there is a starting slash
const testAndAssignStatusId = (id: string) => {
if (!!parseInt(id)) {
statusId = id
}
}
switch (last?.startsWith('@')) {
case true:
if (length === 2 || (length === 3 && segments[length - 2] === 'web')) {
@ -45,14 +50,14 @@ export const urlMatcher = (
if (nextToLast === 'statuses') {
if (length === 4 && segments[length - 3] === 'web') {
// https://social.xmflsct.com/web/statuses/105590085754428765 <- old
statusId = last
testAndAssignStatusId(last)
} else if (
length === 5 &&
segments[length - 2] === 'statuses' &&
segments[length - 4] === 'users'
) {
// https://social.xmflsct.com/users/tooot/statuses/105590085754428765 <- default Mastodon
statusId = last
testAndAssignStatusId(last)
// accountAcct = `@${segments[length - 3]}@${domain}`
}
} 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/@tooot/105590085754428765 <- pretty Mastodon v4.0 and above
statusId = last
testAndAssignStatusId(last)
// accountAcct = `${nextToLast}@${domain}`
}
}
@ -70,7 +75,7 @@ export const urlMatcher = (
return {
domain,
...((accountId || accountAcct) && { account: { id: accountId, acct: accountAcct, _remote } }),
...(accountAcct && { account: { acct: accountAcct, _remote } }),
...(statusId && { status: { id: statusId, _remote } })
}
}

View File

@ -25,7 +25,7 @@ const accountQueryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyA
const match = urlMatcher(key.url)
const domain = match?.domain
const id = key.id || match?.account?.id
const id = key.id
const acct = key.acct || key.username || match?.account?.acct
if (!key._local && domain) {