Composer: Check character limit on edit (#6839)

This commit is contained in:
Alexander Zinchuk 2026-04-14 14:36:21 +02:00
parent 97ba6b8031
commit 854ee08d7e
2 changed files with 30 additions and 24 deletions

View File

@ -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<HTMLDivElement>(editableInputCssSelector);

View File

@ -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,