diff --git a/src/components/middle/composer/Composer.tsx b/src/components/middle/composer/Composer.tsx index dd9769ae..3ab3d8c6 100644 --- a/src/components/middle/composer/Composer.tsx +++ b/src/components/middle/composer/Composer.tsx @@ -162,6 +162,7 @@ const SCREEN_WIDTH_TO_HIDE_PLACEHOLDER = 600; // px const MOBILE_KEYBOARD_HIDE_DELAY_MS = 100; const SELECT_MODE_TRANSITION_MS = 200; +const MESSAGE_MAX_LENGTH = 4096; const CAPTION_MAX_LENGTH = 1024; const SENDING_ANIMATION_DURATION = 350; // eslint-disable-next-line max-len @@ -474,15 +475,17 @@ const Composer: FC = ({ } const { text, entities } = parseMessageInput(htmlRef.current!); + if (!currentAttachments.length && !text && !isForwarding) { return; } - if (currentAttachments.length && text && text.length > CAPTION_MAX_LENGTH) { - const extraLength = text.length - CAPTION_MAX_LENGTH; + const maxLength = currentAttachments.length ? CAPTION_MAX_LENGTH : MESSAGE_MAX_LENGTH; + if (text?.length > maxLength) { + const extraLength = text.length - maxLength; showDialog({ data: { - message: 'CAPTION_TOO_LONG_PLEASE_REMOVE_CHARACTERS', + message: 'MESSAGE_TOO_LONG_PLEASE_REMOVE_CHARACTERS', textParams: { '{EXTRA_CHARS_COUNT}': extraLength, '{PLURAL_S}': extraLength > 1 ? 's' : '', @@ -490,6 +493,7 @@ const Composer: FC = ({ hasErrorKey: true, }, }); + return; } diff --git a/src/components/middle/composer/helpers/parseMessageInput.ts b/src/components/middle/composer/helpers/parseMessageInput.ts index d5f3d622..0b24d099 100644 --- a/src/components/middle/composer/helpers/parseMessageInput.ts +++ b/src/components/middle/composer/helpers/parseMessageInput.ts @@ -16,12 +16,11 @@ const ENTITY_CLASS_BY_NODE_NAME: Record = { }; const MAX_TAG_DEEPNESS = 3; -const MAX_MESSAGE_LENGTH = 4096; export default function parseMessageInput(html: string): ApiFormattedText { const fragment = document.createElement('div'); fragment.innerHTML = parseMarkdown(html); - const text = fragment.innerText.trim().replace(/\u200b+/g, '').slice(0, MAX_MESSAGE_LENGTH); + const text = fragment.innerText.trim().replace(/\u200b+/g, ''); let textIndex = 0; let recursionDeepness = 0; const entities: ApiMessageEntity[] = []; diff --git a/src/util/getReadableErrorText.ts b/src/util/getReadableErrorText.ts index 0f8a0617..ff218355 100644 --- a/src/util/getReadableErrorText.ts +++ b/src/util/getReadableErrorText.ts @@ -40,11 +40,12 @@ const READABLE_ERROR_MESSAGES: Record = { // TODO Bring back after fixing the weird bug // CHANNEL_INVALID: 'An error occurred. Please try again later', LINK_NOT_MODIFIED: 'This discussion is already linked to the channel', + MESSAGE_TOO_LONG: 'Message is too long', // Non-API errors SERVICE_WORKER_DISABLED: 'Service Worker is disabled. Please reload the page without holding key.', // eslint-disable-next-line max-len - CAPTION_TOO_LONG_PLEASE_REMOVE_CHARACTERS: 'The provided caption is too long. Please remove {EXTRA_CHARS_COUNT} character{PLURAL_S}.', + MESSAGE_TOO_LONG_PLEASE_REMOVE_CHARACTERS: 'The provided message is too long. Please remove {EXTRA_CHARS_COUNT} character{PLURAL_S}.', // eslint-disable-next-line max-len FRESH_RESET_AUTHORISATION_FORBIDDEN: 'You can’t logout other sessions if less than 24 hours have passed since you logged on the current session',