This commit is contained in:
xmflsct 2022-12-23 20:02:44 +01:00
parent 3594500b3e
commit 64b367a247
3 changed files with 15 additions and 8 deletions

View File

@ -2,6 +2,7 @@ import Icon from '@components/Icon'
import openLink from '@components/openLink'
import ParseEmojis from '@components/Parse/Emojis'
import CustomText from '@components/Text'
import { getHost } from '@helpers/urlMatcher'
import { useNavigation, useRoute } from '@react-navigation/native'
import { StackNavigationProp } from '@react-navigation/stack'
import { TabLocalStackParamList } from '@utils/navigation/navigators'
@ -13,7 +14,7 @@ import { useTheme } from '@utils/styles/ThemeManager'
import { isEqual } from 'lodash'
import React, { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Platform, Pressable, TextStyleIOS, View } from 'react-native'
import { Pressable, TextStyleIOS, View } from 'react-native'
import HTMLView from 'react-native-htmlview'
import { useSelector } from 'react-redux'
@ -102,7 +103,7 @@ const renderNode = ({
)
}
} else {
const domain = href?.split(new RegExp(/:\/\/(.[^\/]+\/.{3})/))
const host = getHost(href)
// Need example here
const content = node.children && node.children[0] && node.children[0].data
const shouldBeTag = tags && tags.filter(tag => `#${tag.name}` === content).length > 0
@ -127,8 +128,8 @@ const renderNode = ({
}
}}
>
{content && content !== href ? content : showFullLink ? href : domain?.[1]}
{!shouldBeTag ? '...' : null}
{content && content !== href ? content : showFullLink ? href : host}
{!shouldBeTag ? '/...' : null}
</CustomText>
)
}

View File

@ -1,6 +1,13 @@
import { store } from '@root/store'
import { getInstanceUrl } from '@utils/slices/instancesSlice'
const getHost = (url: unknown): string | void => {
if (typeof url !== 'string') return undefined
const matches = url.match(/^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)/i)
return matches?.[1]
}
const matchStatus = (
url: string
): { id: string; style: 'default' | 'pretty'; sameInstance: boolean } | null => {
@ -53,4 +60,4 @@ const matchAccount = (
return null
}
export { matchStatus, matchAccount }
export { getHost, matchStatus, matchAccount }

View File

@ -8,6 +8,7 @@ import {
} from '@tanstack/react-query'
import apiGeneral from '@api/general'
import { PagedResponse } from '@api/helpers'
import { getHost } from '@helpers/urlMatcher'
export type QueryKeyUsers = ['Users', TabSharedStackParamList['Tab-Shared-Users']]
@ -38,9 +39,7 @@ const queryFunction = async ({
let res: PagedResponse<Mastodon.Account[]>
try {
const domain = page.account.url.match(
/^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)/i
)?.[1]
const domain = getHost(page.account.url)
if (!domain?.length) {
throw new Error()
}