diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 94b14fc7b..631a92f94 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -1250,6 +1250,13 @@ MessageReceiver.prototype.extend({ return this.removeFromCache(envelope); } + if (!friendRequest && this.isMessageEmpty(message)) { + window.log.warn( + `Message ${this.getEnvelopeId(envelope)} ignored; it was empty` + ); + return this.removeFromCache(envelope); + } + const ev = new Event('message'); ev.confirm = this.removeFromCache.bind(this, envelope); ev.data = { @@ -1265,6 +1272,27 @@ MessageReceiver.prototype.extend({ }) ); }, + isMessageEmpty({ + body, + attachments, + group, + flags, + quote, + contact, + preview, + groupInvitation, + }) { + return ( + !flags && + _.isEmpty(body) && + _.isEmpty(attachments) && + _.isEmpty(group) && + _.isEmpty(quote) && + _.isEmpty(contact) && + _.isEmpty(preview) && + _.isEmpty(groupInvitation) + ); + }, handleLegacyMessage(envelope) { return this.decrypt(envelope, envelope.legacyMessage).then(plaintext => { if (!plaintext) {