properly shorten links in quote embeds (#2570)

* properly shorten links in quote embeds

* lint
This commit is contained in:
Hailey
2024-01-19 16:15:07 -08:00
committed by GitHub
parent 920d48849e
commit eb07b983bd
3 changed files with 41 additions and 20 deletions
+22 -12
View File
@@ -17,6 +17,7 @@ export function RichText({
lineHeight = 1.2,
style,
numberOfLines,
noLinks,
}: {
testID?: string
type?: TypographyVariant
@@ -24,6 +25,7 @@ export function RichText({
lineHeight?: number
style?: StyleProp<TextStyle>
numberOfLines?: number
noLinks?: boolean
}) {
const theme = useTheme()
const pal = usePalette('default')
@@ -70,7 +72,11 @@ export function RichText({
for (const segment of richText.segments()) {
const link = segment.link
const mention = segment.mention
if (mention && AppBskyRichtextFacet.validateMention(mention).success) {
if (
!noLinks &&
mention &&
AppBskyRichtextFacet.validateMention(mention).success
) {
els.push(
<TextLink
key={key}
@@ -82,17 +88,21 @@ export function RichText({
/>,
)
} else if (link && AppBskyRichtextFacet.validateLink(link).success) {
els.push(
<TextLink
key={key}
type={type}
text={toShortUrl(segment.text)}
href={link.uri}
style={[style, lineHeightStyle, pal.link, {pointerEvents: 'auto'}]}
dataSet={WORD_WRAP}
warnOnMismatchingLabel
/>,
)
if (noLinks) {
els.push(toShortUrl(segment.text))
} else {
els.push(
<TextLink
key={key}
type={type}
text={toShortUrl(segment.text)}
href={link.uri}
style={[style, lineHeightStyle, pal.link, {pointerEvents: 'auto'}]}
dataSet={WORD_WRAP}
warnOnMismatchingLabel
/>,
)
}
} else {
els.push(segment.text)
}