Move to the real verify/trust APIs
This wires up verification sync messages, verification and trust checks to the trust store instead of using mocked data. FREEBIE
This commit is contained in:
parent
52481d1d13
commit
c43d96904d
2 changed files with 26 additions and 38 deletions
|
@ -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('verification sync message', number, verified);
|
||||
console.log('got verification sync for', number, state);
|
||||
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue