From 3851bf351f77f6350cb04385e50494ca39d66e28 Mon Sep 17 00:00:00 2001
From: Scott Nonnenberg <scott@signal.org>
Date: Mon, 10 Dec 2018 10:21:40 -0800
Subject: [PATCH] Throttle typing events, fix profile logging, fix group typing

---
 js/models/conversations.js    | 13 ++++++++-----
 js/views/conversation_view.js |  2 +-
 libtextsecure/crypto.js       |  6 +++---
 libtextsecure/sendmessage.js  |  4 ++--
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/js/models/conversations.js b/js/models/conversations.js
index ef5da5525..98b8377a7 100644
--- a/js/models/conversations.js
+++ b/js/models/conversations.js
@@ -96,6 +96,7 @@
       this.messageCollection.on('change:errors', this.handleMessageError, this);
       this.messageCollection.on('send-error', this.onMessageError, this);
 
+      this.throttledBumpTyping = _.throttle(this.bumpTyping, 300);
       const debouncedUpdateLastMessage = _.debounce(
         this.updateLastMessage.bind(this),
         200
@@ -1502,11 +1503,13 @@
         // This might throw if we can't pull the avatar down, so we do it last
         await c.setProfileAvatar(profile.avatar);
       } catch (error) {
-        window.log.error(
-          'getProfile error:',
-          id,
-          error && error.stack ? error.stack : error
-        );
+        if (error.code !== 403 && error.code !== 404) {
+          window.log.error(
+            'getProfile error:',
+            id,
+            error && error.stack ? error.stack : error
+          );
+        }
       } finally {
         if (c.hasChanged()) {
           await window.Signal.Data.updateConversation(id, c.attributes, {
diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js
index 8a038779d..1d86224c0 100644
--- a/js/views/conversation_view.js
+++ b/js/views/conversation_view.js
@@ -1592,7 +1592,7 @@
     maybeBumpTyping() {
       const messageText = this.$messageField.val();
       if (messageText.length) {
-        this.model.bumpTyping();
+        this.model.throttledBumpTyping();
       }
     },
 
diff --git a/libtextsecure/crypto.js b/libtextsecure/crypto.js
index 9504bd119..7183330a9 100644
--- a/libtextsecure/crypto.js
+++ b/libtextsecure/crypto.js
@@ -90,10 +90,10 @@
 
       return verifyMAC(ivAndCiphertext, macKey, mac, 32)
         .then(() => {
-          if (theirDigest !== null) {
-            return verifyDigest(encryptedBin, theirDigest);
+          if (!theirDigest) {
+            throw new Error('Failure: Ask sender to update Signal and resend.');
           }
-          return null;
+          return verifyDigest(encryptedBin, theirDigest);
         })
         .then(() => decrypt(aesKey, ciphertext, iv));
     },
diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js
index ac138ad78..3daeb86a2 100644
--- a/libtextsecure/sendmessage.js
+++ b/libtextsecure/sendmessage.js
@@ -1,4 +1,4 @@
-/* global textsecure, WebAPI, libsignal, OutgoingMessage, window */
+/* global _, textsecure, WebAPI, libsignal, OutgoingMessage, window */
 
 /* eslint-disable more/no-then, no-bitwise */
 
@@ -533,7 +533,7 @@ MessageSender.prototype = {
     }
 
     const recipients = groupId
-      ? await textsecure.storage.groups.getNumbers(groupId)
+      ? _.without(await textsecure.storage.groups.getNumbers(groupId), myNumber)
       : [recipientId];
     const groupIdBuffer = groupId
       ? window.Signal.Crypto.fromEncodedBinaryToArrayBuffer(groupId)