From 1dd64c4e19c779a9181aeb7128ff0c4e893828ee Mon Sep 17 00:00:00 2001 From: xmflsct Date: Mon, 6 Feb 2023 14:00:40 +0100 Subject: [PATCH] Fix link matching crashes --- package.json | 2 +- src/components/openLink.ts | 10 +--------- src/utils/helpers/urlMatcher.ts | 17 +++++++++++------ src/utils/queryHooks/account.ts | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index d602f225..3264ce49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tooot", - "version": "4.8.7", + "version": "4.8.8", "description": "tooot for Mastodon", "author": "xmflsct ", "license": "GPL-3.0-or-later", diff --git a/src/components/openLink.ts b/src/components/openLink.ts index e5790c28..cf4e5f2f 100644 --- a/src/components/openLink.ts +++ b/src/components/openLink.ts @@ -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(queryKey) if (cache) { diff --git a/src/utils/helpers/urlMatcher.ts b/src/utils/helpers/urlMatcher.ts index 9f70780a..eb3b91c5 100644 --- a/src/utils/helpers/urlMatcher.ts +++ b/src/utils/helpers/urlMatcher.ts @@ -9,7 +9,7 @@ export const urlMatcher = ( ): | { domain: string - account?: Partial> + account?: Partial> status?: Partial> } | 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 } }) } } diff --git a/src/utils/queryHooks/account.ts b/src/utils/queryHooks/account.ts index 61c2bfca..852336b3 100644 --- a/src/utils/queryHooks/account.ts +++ b/src/utils/queryHooks/account.ts @@ -25,7 +25,7 @@ const accountQueryFunction = async ({ queryKey }: QueryFunctionContext