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

View file

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