From 854ee08d7e2795ea5d9c36ee9b4c210583b5e709 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 14 Apr 2026 14:36:21 +0200 Subject: [PATCH] Composer: Check character limit on edit (#6839) --- src/components/common/Composer.tsx | 49 ++++++++++--------- .../middle/composer/hooks/useEditing.ts | 5 ++ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/components/common/Composer.tsx b/src/components/common/Composer.tsx index 71bbfda5d..46ac0999d 100644 --- a/src/components/common/Composer.tsx +++ b/src/components/common/Composer.tsx @@ -931,11 +931,36 @@ const Composer = ({ } }); + const validateTextLength = useLastCallback((text: string, isAttachmentModal?: boolean) => { + const maxLength = isAttachmentModal ? captionLimit : maxMessageLength; + if (text?.length > maxLength) { + const extraLength = text.length - maxLength; + showDialog({ + data: { + type: 'localized', + text: { + key: 'ErrorMessageTooLong', + variables: { + count: extraLength, + }, + options: { + pluralValue: extraLength, + }, + }, + }, + }); + + return false; + } + return true; + }); + const [handleEditComplete, handleEditCancel, shouldForceShowEditing] = useEditing( getHtml, setHtml, editingMessage, resetComposer, + validateTextLength, chatId, threadId, messageListType, @@ -1066,30 +1091,6 @@ const Composer = ({ } }); - const validateTextLength = useLastCallback((text: string, isAttachmentModal?: boolean) => { - const maxLength = isAttachmentModal ? captionLimit : maxMessageLength; - if (text?.length > maxLength) { - const extraLength = text.length - maxLength; - showDialog({ - data: { - type: 'localized', - text: { - key: 'ErrorMessageTooLong', - variables: { - count: extraLength, - }, - options: { - pluralValue: extraLength, - }, - }, - }, - }); - - return false; - } - return true; - }); - const checkSlowMode = useLastCallback(() => { if (slowMode && !isAdmin) { const messageInput = document.querySelector(editableInputCssSelector); diff --git a/src/components/middle/composer/hooks/useEditing.ts b/src/components/middle/composer/hooks/useEditing.ts index a34c72aac..945fce952 100644 --- a/src/components/middle/composer/hooks/useEditing.ts +++ b/src/components/middle/composer/hooks/useEditing.ts @@ -28,6 +28,7 @@ const useEditing = ( setHtml: (html: string) => void, editedMessage: ApiMessage | undefined, resetComposer: (shouldPreserveInput?: boolean) => void, + validateTextLength: (text: string) => boolean, chatId: string, threadId: ThreadId, type: MessageListType, @@ -160,6 +161,10 @@ const useEditing = ( return; } + if (text && !validateTextLength(text)) { + return; + } + editMessage({ messageList: { chatId, threadId, type }, text,