From e57f155403ca7bed67b4fb81a016e153d6d706a9 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 10 Aug 2017 09:30:08 -0700 Subject: [PATCH] Handle rejections from protocol layer (due to missing records) isVerified and isUntrusted both went to the protocol layer, but were not prepared for rejected promises resulting from missing records. This prevented send in large groups where there has never been a message exchanged with one of the members. FREEBIE --- js/models/conversations.js | 23 +++++++++++++++++++---- js/views/conversation_view.js | 15 ++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index f86511faf..3d1ce4dcc 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -62,10 +62,15 @@ onMessageError: function() { this.updateVerified(); }, + safeGetVerified: function() { + return textsecure.storage.protocol.getVerified(this.id).catch(function() { + return textsecure.storage.protocol.VerifiedStatus.DEFAULT; + }); + }, updateVerified: function() { if (this.isPrivate()) { return Promise.all([ - textsecure.storage.protocol.getVerified(this.id), + this.safeGetVerified(), this.safeFetch() ]).then(function(results) { var trust = results[0]; @@ -220,9 +225,14 @@ return textsecure.storage.protocol.setApproval(this.id, true); }, + safeIsUntrusted: function() { + return textsecure.storage.protocol.isUntrusted(this.id).catch(function() { + return false; + }); + }, isUntrusted: function() { if (this.isPrivate()) { - return textsecure.storage.protocol.isUntrusted(this.id); + return this.safeIsUntrusted(); } else { if (!this.contactCollection.length) { return Promise.resolve(false); @@ -232,7 +242,7 @@ if (contact.isMe()) { return false; } else { - return contact.isUntrusted(); + return contact.safeIsUntrusted(); } }.bind(this))).then(function(results) { return _.any(results, function(result) { @@ -257,7 +267,7 @@ if (contact.isMe()) { return [false, contact]; } else { - return Promise.all([this.isUntrusted(), contact]); + return Promise.all([contact.isUntrusted(), contact]); } }.bind(this))).then(function(results) { results = _.filter(results, function(result) { @@ -653,6 +663,11 @@ return sessionCipher.closeOpenSessionForDevice(); } }); + }).catch(function(error) { + console.log( + 'getProfile error:', + error && error.stack ? error.stack : error + ); }); }, diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 03a09bcd7..43e4f904a 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -875,7 +875,12 @@ } this.showSendConfirmationDialog(e, contacts); - }.bind(this)); + }.bind(this)).catch(function(error) { + console.log( + 'checkUnverifiedSendMessage error:', + error && error.stack ? error.stack : error + ); + }); }, checkUntrustedSendMessage: function(e, options) { @@ -883,7 +888,6 @@ _.defaults(options, {force: false}); this.model.getUntrusted().then(function(contacts) { - if (!contacts.length) { return this.sendMessage(e); } @@ -895,7 +899,12 @@ } this.showSendConfirmationDialog(e, contacts); - }.bind(this)); + }.bind(this)).catch(function(error) { + console.log( + 'checkUntrustedSendMessage error:', + error && error.stack ? error.stack : error + ); + }); }, sendMessage: function(e) {