diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 023acd9e3..e67f64278 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1378,6 +1378,10 @@ "description": "Timestamp format string for displaying month and day (but not the year) of a date within the current year, ex: use 'MMM D' for 'Aug 8', or 'D MMM' for '8 Aug'." }, + "messageBodyTooLong": { + "message": "Message body is too long.", + "description": "Shown if the user tries to send more than 64kb of text" + }, "unblockToSend": { "message": "Unblock this contact to send a message.", "description": "Brief message shown when trying to message a blocked number" diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 68ab3eb25..6a0b8ad21 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -64,6 +64,13 @@ }, }); + const MAX_MESSAGE_BODY_LENGTH = 64 * 1024; + Whisper.MessageBodyTooLongToast = Whisper.ToastView.extend({ + render_attributes() { + return { toastMessage: i18n('messageBodyTooLong') }; + }, + }); + Whisper.ConversationLoadingScreen = Whisper.View.extend({ templateName: 'conversation-loading-screen', className: 'conversation-loading-screen', @@ -1653,6 +1660,9 @@ this.closeEmojiPanel(); this.model.clearTypingTimers(); + const input = this.$messageField; + const message = window.Signal.Emoji.replaceColons(input.val()).trim(); + let toast; if (extension.expired()) { toast = new Whisper.ExpiredToast(); @@ -1666,6 +1676,9 @@ if (!this.model.isPrivate() && this.model.get('left')) { toast = new Whisper.LeftGroupToast(); } + if (message.length > MAX_MESSAGE_BODY_LENGTH) { + toast = new Whisper.MessageBodyTooLongToast(); + } if (toast) { toast.$el.appendTo(this.$el); @@ -1674,9 +1687,6 @@ return; } - const input = this.$messageField; - const message = window.Signal.Emoji.replaceColons(input.val()).trim(); - try { if (!message.length && !this.fileInput.hasFiles()) { return;