From b46ed237b381d45fcf56fac9152ba61cc50d27ef Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 20 Oct 2020 15:02:16 +1100 Subject: [PATCH] allow empty message when they have attachments --- _locales/en/messages.json | 6 +++++- .../conversation/SessionCompositionBox.tsx | 11 ++++++----- ts/session/utils/Toast.ts | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 47c653fe9..bc650b908 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1275,7 +1275,11 @@ }, "messageBodyTooLong": { "message": "Message body is too long.", - "description": "Shown if the user tries to send more than 64kb of text" + "description": "Shown if the user tries to send more than MAX_MESSAGE_BODY_LENGTH chars" + }, + "messageBodyMissing": { + "message": "Please enter a message body.", + "description": "Shown if the user tries to send an empty message (and no attachments)" }, "unblockToSend": { "message": "Unblock this contact to send a message.", diff --git a/ts/components/session/conversation/SessionCompositionBox.tsx b/ts/components/session/conversation/SessionCompositionBox.tsx index 600ba47b1..075885077 100644 --- a/ts/components/session/conversation/SessionCompositionBox.tsx +++ b/ts/components/session/conversation/SessionCompositionBox.tsx @@ -325,13 +325,14 @@ export class SessionCompositionBox extends React.Component { private async onSendMessage() { const messagePlaintext = this.parseEmojis(this.state.message); - if (!messagePlaintext) { + // Verify message length + const msgLen = messagePlaintext?.length || 0; + if (msgLen > window.CONSTANTS.MAX_MESSAGE_BODY_LENGTH) { + ToastUtils.pushMessageBodyTooLong(); return; } - - // Verify message length - const msgLen = messagePlaintext.length; - if (msgLen === 0 || msgLen > window.CONSTANTS.MAX_MESSAGE_BODY_LENGTH) { + if (msgLen === 0 && this.state.stagedAttachments?.length === 0) { + ToastUtils.pushMessageBodyMissing(); return; } const { quotedMessageProps } = this.props; diff --git a/ts/session/utils/Toast.ts b/ts/session/utils/Toast.ts index b60f89e1f..0c5d70413 100644 --- a/ts/session/utils/Toast.ts +++ b/ts/session/utils/Toast.ts @@ -57,3 +57,19 @@ export function pushMaximumAttachmentsError() { id: 'maximumAttachments', }); } + +export function pushMessageBodyTooLong() { + window.pushToast({ + title: window.i18n('messageBodyTooLong'), + type: 'error', + id: 'messageBodyTooLong', + }); +} + +export function pushMessageBodyMissing() { + window.pushToast({ + title: window.i18n('messageBodyMissing'), + type: 'error', + id: 'messageBodyMissing', + }); +}