Show verified/keychange notifications when actually relevant

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-07-03 17:31:57 -07:00
parent 3d445fe549
commit 20451cc827
6 changed files with 52 additions and 14 deletions

View file

@ -315,10 +315,16 @@
return;
}
var options = {
viaSyncMessage: true,
viaContactSync: ev.viaContactSync,
key: key
};
if (state === 'DEFAULT') {
contact.setVerifiedDefault({viaSyncMessage: true, key: key});
contact.setVerifiedDefault(options);
} else if (state === 'VERIFIED') {
contact.setVerified({viaSyncMessage: true, key: key});
contact.setVerified(options);
}
}

View file

@ -38493,13 +38493,17 @@ MessageReceiver.prototype.extend({
throw new Error('Got empty SyncMessage');
}
},
handleVerified: function(verified) {
handleVerified: function(verified, options) {
options = options || {};
_.defaults(options, {viaContactSync: false});
var ev = new Event('verified');
ev.verified = {
state: verified.state,
destination: verified.destination,
identityKey: verified.identityKey.toArrayBuffer()
};
ev.viaContactSync = options.viaContactSync;
this.dispatchEvent(ev);
},
handleRead: function(read, timestamp) {
@ -38526,7 +38530,7 @@ MessageReceiver.prototype.extend({
eventTarget.dispatchEvent(ev);
if (contactDetails.verified) {
this.handleVerified(contactDetails.verified);
this.handleVerified(contactDetails.verified, {viaContactSync: true});
}
contactDetails = contactBuffer.next();

View file

@ -82,23 +82,29 @@
},
setVerifiedDefault: function(options) {
var DEFAULT = this.verifiedEnum.DEFAULT;
return this._setVerified(DEFAULT, options);
return this.queueJob(function() {
return this._setVerified(DEFAULT, options);
}.bind(this));
},
setVerified: function(options) {
var VERIFIED = this.verifiedEnum.VERIFIED;
return this._setVerified(VERIFIED, options);
return this.queueJob(function() {
return this._setVerified(VERIFIED, options);
}.bind(this));
},
_setVerified: function(verified, options) {
options = options || {};
_.defaults(options, {viaSyncMessage: false, key: null});
_.defaults(options, {viaSyncMessage: false, viaContactSync: false, key: null});
var VERIFIED = this.verifiedEnum.VERIFIED;
var DEFAULT = this.verifiedEnum.DEFAULT;
if (!this.isPrivate()) {
throw new Error('You cannot verify a group conversation. ' +
'You must verify individual contacts.');
}
var beginningVerified = this.get('verified');
var promise;
if (options.viaSyncMessage) {
// handle the incoming key from the sync messages - need different
@ -112,10 +118,25 @@
);
}
return promise.then(function() {
var keychange;
return promise.then(function(updatedKey) {
keychange = updatedKey;
return this.save({verified: verified});
}.bind(this)).then(function() {
this.addVerifiedChange(this.id, verified === VERIFIED, {local: !options.viaSyncMessage});
// Three situations result in a verification notice in the conversation:
// 1) The message came from an explicit verification in another client (not
// a contact sync)
// 2) The verification value received by the contact sync is different
// from what we have on record
// 3) Our local verification status is not DEFAULT and it hasn't changed,
// but the key did change (say from Key1/Verified to Key2/Verified)
if (!options.viaContactSync
|| beginningVerified !== verified
|| (keychange && verified !== DEFAULT)) {
var local = !options.viaSyncMessage && !options.viaContactSync;
this.addVerifiedChange(this.id, verified === VERIFIED, {local: local});
}
if (!options.viaSyncMessage) {
return this.sendVerifySyncMessage(this.id, verified);
}

View file

@ -625,9 +625,12 @@
timestamp : Date.now(),
nonblockingApproval : true
}).then(function() {
if (!isPresent || !isEqual) {
if (isPresent && !isEqual) {
this.trigger('keychange', identifier);
return this.archiveAllSessions(identifier).then(resolve, reject);
return this.archiveAllSessions(identifier).then(function() {
// true signifies that we overwrote a previous key with a new one
return resolve(true);
}, reject);
}
return resolve();

View file

@ -284,13 +284,17 @@ MessageReceiver.prototype.extend({
throw new Error('Got empty SyncMessage');
}
},
handleVerified: function(verified) {
handleVerified: function(verified, options) {
options = options || {};
_.defaults(options, {viaContactSync: false});
var ev = new Event('verified');
ev.verified = {
state: verified.state,
destination: verified.destination,
identityKey: verified.identityKey.toArrayBuffer()
};
ev.viaContactSync = options.viaContactSync;
this.dispatchEvent(ev);
},
handleRead: function(read, timestamp) {
@ -317,7 +321,7 @@ MessageReceiver.prototype.extend({
eventTarget.dispatchEvent(ev);
if (contactDetails.verified) {
this.handleVerified(contactDetails.verified);
this.handleVerified(contactDetails.verified, {viaContactSync: true});
}
contactDetails = contactBuffer.next();

View file

@ -442,7 +442,7 @@ describe("SignalProtocolStore", function() {
).then(fetchRecord).then(function() {
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
assertEqualArrayBuffers(record.get('publicKey'), newIdentity);
assert.strictEqual(keychangeTriggered, 1);
assert.strictEqual(keychangeTriggered, 0);
});
});
});