From e0d719457f2b180a4ce6156de2519ca1af69deaa Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 24 Jan 2025 11:22:45 +1100 Subject: [PATCH] feat: limit input of composition box to 2000 char --- .../conversation/composition/CompositionTextArea.tsx | 7 ++++++- ts/session/constants.ts | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ts/components/conversation/composition/CompositionTextArea.tsx b/ts/components/conversation/composition/CompositionTextArea.tsx index 7439900be..b533982b7 100644 --- a/ts/components/conversation/composition/CompositionTextArea.tsx +++ b/ts/components/conversation/composition/CompositionTextArea.tsx @@ -12,6 +12,7 @@ import { renderEmojiQuickResultRow, searchEmojiForQuery } from './EmojiQuickResu import { renderUserMentionRow, styleForCompositionBoxSuggestions } from './UserMentions'; import { HTMLDirection, useHTMLDirection } from '../../../util/i18n/rtlSupport'; import { ConvoHub } from '../../../session/conversations'; +import { Constants } from '../../../session'; const sendMessageStyle = (dir?: HTMLDirection) => { return { @@ -87,7 +88,10 @@ export const CompositionTextArea = (props: Props) => { throw new Error('selectedConversationKey is needed'); } - const newDraft = event.target.value ?? ''; + const newDraft = (event.target.value ?? '').slice( + 0, + Constants.CONVERSATION.MAX_MESSAGE_CHAR_COUNT + ); setDraft(newDraft); updateDraftForConversation({ conversationKey: selectedConversationKey, draft: newDraft }); }; @@ -121,6 +125,7 @@ export const CompositionTextArea = (props: Props) => { spellCheck={true} dir={htmlDirection} inputRef={textAreaRef} + maxLength={Constants.CONVERSATION.MAX_MESSAGE_CHAR_COUNT} disabled={!typingEnabled} rows={1} data-testid="message-input-text-area" diff --git a/ts/session/constants.ts b/ts/session/constants.ts index 5dafa06ae..0ef7e7486 100644 --- a/ts/session/constants.ts +++ b/ts/session/constants.ts @@ -77,6 +77,11 @@ export const CONVERSATION = { MAX_GLOBAL_UNREAD_COUNT: 99, // the global one does not look good with 4 digits (999+) so we have a smaller one for it /** NOTE some existing groups might not have joinedAtSeconds and we need a fallback value that is not falsy in order to poll and show up in the conversations list */ LAST_JOINED_FALLBACK_TIMESTAMP: 1, + /** + * the maximum chars that can be typed/pasted in the composition box. + * Same as android. + */ + MAX_MESSAGE_CHAR_COUNT: 2000, } as const; /**