Use shouldLinkifyMessage in MessageBody/ReadMore

This commit is contained in:
Scott Nonnenberg 2023-08-16 16:06:40 -07:00 committed by Jamie Kyle
parent 8b0da36caa
commit 7969dd881e
2 changed files with 7 additions and 2 deletions

View file

@ -14,6 +14,7 @@ import type { LocalizerType } from '../../types/Util';
import { MessageTextRenderer } from './MessageTextRenderer';
import type { RenderLocation } from './MessageTextRenderer';
import { UserText } from '../UserText';
import { shouldLinkifyMessage } from '../../types/LinkPreview';
export type Props = {
author?: string;
@ -59,6 +60,8 @@ export function MessageBody({
textAttachment,
}: Props): JSX.Element {
const hasReadMore = Boolean(onIncreaseTextLength);
const shouldDisableLinks = disableLinks || !shouldLinkifyMessage(text);
const textWithSuffix =
textAttachment?.pending || hasReadMore ? `${text}...` : text;
@ -119,7 +122,7 @@ export function MessageBody({
<MessageTextRenderer
bodyRanges={bodyRanges ?? []}
direction={direction}
disableLinks={disableLinks ?? false}
disableLinks={shouldDisableLinks}
emojiSizeClass={sizeClass}
i18n={i18n}
isSpoilerExpanded={isSpoilerExpanded}

View file

@ -6,6 +6,7 @@ import React from 'react';
import type { Props as MessageBodyPropsType } from './MessageBody';
import { MessageBody } from './MessageBody';
import { graphemeAndLinkAwareSlice } from '../../util/graphemeAndLinkAwareSlice';
import { shouldLinkifyMessage } from '../../types/LinkPreview';
export type Props = Pick<
MessageBodyPropsType,
@ -52,6 +53,7 @@ export function MessageBodyReadMore({
}: Props): JSX.Element {
const maxLength = displayLimit || INITIAL_LENGTH;
const shouldDisableLinks = disableLinks || !shouldLinkifyMessage(text);
const { hasReadMore, text: slicedText } = graphemeAndLinkAwareSlice(
text,
maxLength,
@ -71,7 +73,7 @@ export function MessageBodyReadMore({
bodyRanges={bodyRanges}
direction={direction}
disableJumbomoji={disableJumbomoji}
disableLinks={disableLinks}
disableLinks={shouldDisableLinks}
i18n={i18n}
isSpoilerExpanded={isSpoilerExpanded}
kickOffBodyDownload={kickOffBodyDownload}