Don't send if message body is too long

This commit is contained in:
Scott Nonnenberg 2019-04-12 14:54:45 -07:00
parent 6cf4f19317
commit b31fbcaa17
2 changed files with 17 additions and 3 deletions

View File

@ -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"

View File

@ -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;