Fixes #1143 Disallow sending of empty messages

This commit is contained in:
JC Brand 2018-08-01 18:46:52 +02:00
parent f120fbd209
commit b027f0f784
3 changed files with 13 additions and 9 deletions

View File

@ -30,6 +30,7 @@
- Documentation includes utf-8 charset to make minfied versions compatible across platforms. #1017 - Documentation includes utf-8 charset to make minfied versions compatible across platforms. #1017
- #1026 Typing in MUC shows "Typing from another device" - #1026 Typing in MUC shows "Typing from another device"
- #1039 Multi-option data form elements not shown and saved correctly - #1039 Multi-option data form elements not shown and saved correctly
- #1143 Able to send blank message
### API changes ### API changes

12
dist/converse.js vendored
View File

@ -70266,6 +70266,11 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
ev.preventDefault(); ev.preventDefault();
const textarea = this.el.querySelector('.chat-textarea'), const textarea = this.el.querySelector('.chat-textarea'),
message = textarea.value; message = textarea.value;
if (!message.replace(/\s/g, '').length) {
return;
}
let spoiler_hint; let spoiler_hint;
if (this.model.get('composing_spoiler')) { if (this.model.get('composing_spoiler')) {
@ -70280,12 +70285,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
const event = document.createEvent('Event'); const event = document.createEvent('Event');
event.initEvent('input', true, true); event.initEvent('input', true, true);
textarea.dispatchEvent(event); textarea.dispatchEvent(event);
this.onMessageSubmitted(message, spoiler_hint);
if (message !== '') { _converse.emit('messageSend', message);
this.onMessageSubmitted(message, spoiler_hint);
_converse.emit('messageSend', message);
}
this.setChatState(_converse.ACTIVE); this.setChatState(_converse.ACTIVE);
}, },

View File

@ -890,6 +890,9 @@
const textarea = this.el.querySelector('.chat-textarea'), const textarea = this.el.querySelector('.chat-textarea'),
message = textarea.value; message = textarea.value;
if (!message.replace(/\s/g, '').length) {
return;
}
let spoiler_hint; let spoiler_hint;
if (this.model.get('composing_spoiler')) { if (this.model.get('composing_spoiler')) {
const hint_el = this.el.querySelector('form.sendXMPPMessage input.spoiler-hint'); const hint_el = this.el.querySelector('form.sendXMPPMessage input.spoiler-hint');
@ -903,10 +906,8 @@
event.initEvent('input', true, true); event.initEvent('input', true, true);
textarea.dispatchEvent(event); textarea.dispatchEvent(event);
if (message !== '') { this.onMessageSubmitted(message, spoiler_hint);
this.onMessageSubmitted(message, spoiler_hint); _converse.emit('messageSend', message);
_converse.emit('messageSend', message);
}
this.setChatState(_converse.ACTIVE); this.setChatState(_converse.ACTIVE);
}, },