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
pull/749/head
Scott Nonnenberg 8 years ago
parent 50927c0eba
commit e57f155403

@ -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
);
});
},

@ -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) {

Loading…
Cancel
Save