Composer: Check character limit on edit (#6839)
This commit is contained in:
parent
97ba6b8031
commit
854ee08d7e
@ -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(
|
const [handleEditComplete, handleEditCancel, shouldForceShowEditing] = useEditing(
|
||||||
getHtml,
|
getHtml,
|
||||||
setHtml,
|
setHtml,
|
||||||
editingMessage,
|
editingMessage,
|
||||||
resetComposer,
|
resetComposer,
|
||||||
|
validateTextLength,
|
||||||
chatId,
|
chatId,
|
||||||
threadId,
|
threadId,
|
||||||
messageListType,
|
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(() => {
|
const checkSlowMode = useLastCallback(() => {
|
||||||
if (slowMode && !isAdmin) {
|
if (slowMode && !isAdmin) {
|
||||||
const messageInput = document.querySelector<HTMLDivElement>(editableInputCssSelector);
|
const messageInput = document.querySelector<HTMLDivElement>(editableInputCssSelector);
|
||||||
|
|||||||
@ -28,6 +28,7 @@ const useEditing = (
|
|||||||
setHtml: (html: string) => void,
|
setHtml: (html: string) => void,
|
||||||
editedMessage: ApiMessage | undefined,
|
editedMessage: ApiMessage | undefined,
|
||||||
resetComposer: (shouldPreserveInput?: boolean) => void,
|
resetComposer: (shouldPreserveInput?: boolean) => void,
|
||||||
|
validateTextLength: (text: string) => boolean,
|
||||||
chatId: string,
|
chatId: string,
|
||||||
threadId: ThreadId,
|
threadId: ThreadId,
|
||||||
type: MessageListType,
|
type: MessageListType,
|
||||||
@ -160,6 +161,10 @@ const useEditing = (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (text && !validateTextLength(text)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
editMessage({
|
editMessage({
|
||||||
messageList: { chatId, threadId, type },
|
messageList: { chatId, threadId, type },
|
||||||
text,
|
text,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user