From 13832f83bbcd8f4d1f78d020fd9b8537db729a01 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 13 May 2020 10:59:25 +1000 Subject: [PATCH 1/2] Stop processing message when it is empty --- libtextsecure/message_receiver.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 94b14fc7b..86806920f 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -1250,6 +1250,15 @@ 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 +1274,9 @@ 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) { From 873dadef48ec8afd9ab68fffae9b9802c272cfb6 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 13 May 2020 11:00:38 +1000 Subject: [PATCH 2/2] Lint --- libtextsecure/message_receiver.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 86806920f..631a92f94 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -1252,9 +1252,7 @@ MessageReceiver.prototype.extend({ if (!friendRequest && this.isMessageEmpty(message)) { window.log.warn( - `Message ${this.getEnvelopeId( - envelope - )} ignored; it was empty` + `Message ${this.getEnvelopeId(envelope)} ignored; it was empty` ); return this.removeFromCache(envelope); } @@ -1274,8 +1272,26 @@ 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) + 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 => {