Introduce smaller incoming size limit for text attachments

This commit is contained in:
Scott Nonnenberg 2023-12-18 10:14:59 -08:00 committed by GitHub
parent 8c71ed2590
commit 5e733059b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 31 deletions

View file

@ -33,7 +33,10 @@ export type Props = {
renderLocation: RenderLocation;
showConversation?: ShowConversationType;
text: string;
textAttachment?: Pick<AttachmentType, 'pending' | 'digest' | 'key'>;
textAttachment?: Pick<
AttachmentType,
'pending' | 'digest' | 'key' | 'wasTooBig'
>;
};
/**
@ -59,19 +62,36 @@ export function MessageBody({
text,
textAttachment,
}: Props): JSX.Element {
const hasReadMore = Boolean(onIncreaseTextLength);
const shouldDisableLinks = disableLinks || !shouldLinkifyMessage(text);
const textWithSuffix =
textAttachment?.pending || hasReadMore ? `${text}...` : text;
textAttachment?.pending || onIncreaseTextLength || textAttachment?.wasTooBig
? `${text}...`
: text;
const sizeClass = disableJumbomoji ? undefined : getSizeClass(text);
let pendingContent: React.ReactNode;
if (hasReadMore) {
pendingContent = null;
let endNotification: React.ReactNode;
if (onIncreaseTextLength) {
endNotification = (
<button
className="MessageBody__read-more"
onClick={() => {
onIncreaseTextLength();
}}
onKeyDown={(ev: KeyboardEvent) => {
if (ev.key === 'Space' || ev.key === 'Enter') {
onIncreaseTextLength();
}
}}
tabIndex={0}
type="button"
>
{' '}
{i18n('icu:MessageBody--read-more')}
</button>
);
} else if (textAttachment?.pending) {
pendingContent = (
endNotification = (
<span className="MessageBody__highlight"> {i18n('icu:downloading')}</span>
);
} else if (
@ -79,7 +99,7 @@ export function MessageBody({
canBeDownloaded(textAttachment) &&
kickOffBodyDownload
) {
pendingContent = (
endNotification = (
<span>
{' '}
<button
@ -99,8 +119,14 @@ export function MessageBody({
</button>
</span>
);
} else if (textAttachment?.wasTooBig) {
endNotification = (
<span className="MessageBody__message-too-long">
{' '}
{i18n('icu:MessageBody--message-too-long')}
</span>
);
}
return (
<span>
{author && (
@ -135,25 +161,7 @@ export function MessageBody({
textLength={text.length}
/>
{pendingContent}
{onIncreaseTextLength ? (
<button
className="MessageBody__read-more"
onClick={() => {
onIncreaseTextLength();
}}
onKeyDown={(ev: KeyboardEvent) => {
if (ev.key === 'Space' || ev.key === 'Enter') {
onIncreaseTextLength();
}
}}
tabIndex={0}
type="button"
>
{' '}
{i18n('icu:MessageBody--read-more')}
</button>
) : null}
{endNotification}
</span>
);
}