diff --git a/js/background.js b/js/background.js index 979fd8252..ef71ce6f4 100644 --- a/js/background.js +++ b/js/background.js @@ -119,7 +119,7 @@ messageReceiver.addEventListener('group', onGroupReceived); messageReceiver.addEventListener('sent', onSentMessage); messageReceiver.addEventListener('read', onReadReceipt); - messageReceiver.addEventListener('verification', onVerify); + messageReceiver.addEventListener('verification', onVerification); messageReceiver.addEventListener('error', onError); @@ -291,23 +291,33 @@ }); } - var VERIFIED_ENUM = textsecure.storage.protocol.VerifiedStatus; - - function onVerify(ev) { + function onVerification(ev) { var number = ev.destination; var key = ev.identityKey; - var verified = ev.state; + var state; + + console.log('got verification sync for', number, state); - console.log('verification sync message', number, verified); + switch(ev.state) { + case textsecure.protobuf.Verification.State.DEFAULT: + state = 'DEFAULT'; + break; + case textsecure.protobuf.Verification.State.VERIFIED: + state = 'VERIFIED'; + break; + case textsecure.protobuf.Verification.State.NO_LONGER_VERIFIED: + state = 'UNVERIFIED'; + break; + } var contact = ConversationController.get(number); if (!contact) { return; } - if (verified === VERIFIED_ENUM.DEFAULT) { + if (state === 'DEFAULT') { contact.setVerifiedDefault({viaSyncMessage: true, key: key}); - } else if (verified === VERIFIED_ENUM.VERIFIED) { + } else if (state === 'VERIFIED') { contact.setVerified({viaSyncMessage: true, key: key}); } } diff --git a/js/models/conversations.js b/js/models/conversations.js index 28dd02360..dc8f2be99 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -38,12 +38,7 @@ initialize: function() { this.ourNumber = textsecure.storage.user.getNumber(); - // this.verifiedEnum = textsecure.storage.protocol.VerifiedStatus; - this.verifiedEnum = { - DEFAULT: 0, - VERIFIED: 1, - UNVERIFIED: 2, - }; + this.verifiedEnum = textsecure.storage.protocol.VerifiedStatus; this.contactCollection = new Backbone.Collection(); this.messageCollection = new Whisper.MessageCollection([], { @@ -61,14 +56,9 @@ }, updateVerified: function() { - function checkTrustStore(value) { - return Promise.resolve(value); - } - if (this.isPrivate()) { return Promise.all([ - //textsecure.storage.protocol.getVerified(this.id), - checkTrustStore(this.verifiedEnum.UNVERIFIED), + textsecure.storage.protocol.getVerified(this.id), this.fetch() ]).then(function(results) { var trust = results[0]; @@ -94,11 +84,7 @@ } var DEFAULT = this.verifiedEnum.DEFAULT; - // return textsecure.storage.protocol.setVerified(this.id, DEFAULT, options.key).then(function() { - function updateTrustStore() { - return Promise.resolve(); - } - return updateTrustStore(this.id, DEFAULT, options.key).then(function() { + return textsecure.storage.protocol.setVerified(this.id, DEFAULT, options.key).then(function() { return this.save({verified: DEFAULT}); }.bind(this)).then(function() { this.addVerifiedChange(this.id, false); @@ -118,11 +104,7 @@ 'You must verify individual contacts.'); } - // return textsecure.storage.protocol.setVerified(this.id, VERIFIED, options.key).then(function() { - function updateTrustStore() { - return Promise.resolve(); - } - return updateTrustStore(this.id, VERIFIED, options.key).then(function() { + return textsecure.storage.protocol.setVerified(this.id, VERIFIED, options.key).then(function() { return this.save({verified: VERIFIED}); }.bind(this)).then(function() { this.addVerifiedChange(this.id, true); @@ -132,9 +114,9 @@ }.bind(this)); }, sendVerifySyncMessage: function(number, state) { - // textsecure.storage.protocol.loadIdentityKey(number).then(function(key) { - // textsecure.storage.protocol.sendVerifySync(number, state, key); - // }); + textsecure.storage.protocol.loadIdentityKey(number).then(function(key) { + textsecure.storage.protocol.syncVerification(number, state, key); + }); }, isVerified: function() { if (this.isPrivate()) { @@ -186,11 +168,7 @@ }, isUntrusted: function() { if (this.isPrivate()) { - // return textsecure.storage.protocol.isUntrusted(this.id); - function getFromTrustStore() { - return Promise.resolve(true); - } - return getFromTrustStore(this.id); + return textsecure.storage.protocol.isUntrusted(this.id); } else { if (!this.contactCollection.length) { return Promise.resolve(false);