Composer: Notify user if message is too long
This commit is contained in:
parent
2a9f4f7d63
commit
08e084344d
@ -162,6 +162,7 @@ const SCREEN_WIDTH_TO_HIDE_PLACEHOLDER = 600; // px
|
|||||||
|
|
||||||
const MOBILE_KEYBOARD_HIDE_DELAY_MS = 100;
|
const MOBILE_KEYBOARD_HIDE_DELAY_MS = 100;
|
||||||
const SELECT_MODE_TRANSITION_MS = 200;
|
const SELECT_MODE_TRANSITION_MS = 200;
|
||||||
|
const MESSAGE_MAX_LENGTH = 4096;
|
||||||
const CAPTION_MAX_LENGTH = 1024;
|
const CAPTION_MAX_LENGTH = 1024;
|
||||||
const SENDING_ANIMATION_DURATION = 350;
|
const SENDING_ANIMATION_DURATION = 350;
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
@ -474,15 +475,17 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { text, entities } = parseMessageInput(htmlRef.current!);
|
const { text, entities } = parseMessageInput(htmlRef.current!);
|
||||||
|
|
||||||
if (!currentAttachments.length && !text && !isForwarding) {
|
if (!currentAttachments.length && !text && !isForwarding) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentAttachments.length && text && text.length > CAPTION_MAX_LENGTH) {
|
const maxLength = currentAttachments.length ? CAPTION_MAX_LENGTH : MESSAGE_MAX_LENGTH;
|
||||||
const extraLength = text.length - CAPTION_MAX_LENGTH;
|
if (text?.length > maxLength) {
|
||||||
|
const extraLength = text.length - maxLength;
|
||||||
showDialog({
|
showDialog({
|
||||||
data: {
|
data: {
|
||||||
message: 'CAPTION_TOO_LONG_PLEASE_REMOVE_CHARACTERS',
|
message: 'MESSAGE_TOO_LONG_PLEASE_REMOVE_CHARACTERS',
|
||||||
textParams: {
|
textParams: {
|
||||||
'{EXTRA_CHARS_COUNT}': extraLength,
|
'{EXTRA_CHARS_COUNT}': extraLength,
|
||||||
'{PLURAL_S}': extraLength > 1 ? 's' : '',
|
'{PLURAL_S}': extraLength > 1 ? 's' : '',
|
||||||
@ -490,6 +493,7 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
hasErrorKey: true,
|
hasErrorKey: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,12 +16,11 @@ const ENTITY_CLASS_BY_NODE_NAME: Record<string, string> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const MAX_TAG_DEEPNESS = 3;
|
const MAX_TAG_DEEPNESS = 3;
|
||||||
const MAX_MESSAGE_LENGTH = 4096;
|
|
||||||
|
|
||||||
export default function parseMessageInput(html: string): ApiFormattedText {
|
export default function parseMessageInput(html: string): ApiFormattedText {
|
||||||
const fragment = document.createElement('div');
|
const fragment = document.createElement('div');
|
||||||
fragment.innerHTML = parseMarkdown(html);
|
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 textIndex = 0;
|
||||||
let recursionDeepness = 0;
|
let recursionDeepness = 0;
|
||||||
const entities: ApiMessageEntity[] = [];
|
const entities: ApiMessageEntity[] = [];
|
||||||
|
|||||||
@ -40,11 +40,12 @@ const READABLE_ERROR_MESSAGES: Record<string, string> = {
|
|||||||
// TODO Bring back after fixing the weird bug
|
// TODO Bring back after fixing the weird bug
|
||||||
// CHANNEL_INVALID: 'An error occurred. Please try again later',
|
// CHANNEL_INVALID: 'An error occurred. Please try again later',
|
||||||
LINK_NOT_MODIFIED: 'This discussion is already linked to the channel',
|
LINK_NOT_MODIFIED: 'This discussion is already linked to the channel',
|
||||||
|
MESSAGE_TOO_LONG: 'Message is too long',
|
||||||
|
|
||||||
// Non-API errors
|
// Non-API errors
|
||||||
SERVICE_WORKER_DISABLED: 'Service Worker is disabled. Please reload the page without holding <Shift> key.',
|
SERVICE_WORKER_DISABLED: 'Service Worker is disabled. Please reload the page without holding <Shift> key.',
|
||||||
// eslint-disable-next-line max-len
|
// 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
|
// 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',
|
FRESH_RESET_AUTHORISATION_FORBIDDEN: 'You can’t logout other sessions if less than 24 hours have passed since you logged on the current session',
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user