Show verified/keychange notifications when actually relevant
FREEBIE
This commit is contained in:
parent
3d445fe549
commit
20451cc827
6 changed files with 52 additions and 14 deletions
|
@ -315,10 +315,16 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
viaSyncMessage: true,
|
||||||
|
viaContactSync: ev.viaContactSync,
|
||||||
|
key: key
|
||||||
|
};
|
||||||
|
|
||||||
if (state === 'DEFAULT') {
|
if (state === 'DEFAULT') {
|
||||||
contact.setVerifiedDefault({viaSyncMessage: true, key: key});
|
contact.setVerifiedDefault(options);
|
||||||
} else if (state === 'VERIFIED') {
|
} else if (state === 'VERIFIED') {
|
||||||
contact.setVerified({viaSyncMessage: true, key: key});
|
contact.setVerified(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38493,13 +38493,17 @@ MessageReceiver.prototype.extend({
|
||||||
throw new Error('Got empty SyncMessage');
|
throw new Error('Got empty SyncMessage');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleVerified: function(verified) {
|
handleVerified: function(verified, options) {
|
||||||
|
options = options || {};
|
||||||
|
_.defaults(options, {viaContactSync: false});
|
||||||
|
|
||||||
var ev = new Event('verified');
|
var ev = new Event('verified');
|
||||||
ev.verified = {
|
ev.verified = {
|
||||||
state: verified.state,
|
state: verified.state,
|
||||||
destination: verified.destination,
|
destination: verified.destination,
|
||||||
identityKey: verified.identityKey.toArrayBuffer()
|
identityKey: verified.identityKey.toArrayBuffer()
|
||||||
};
|
};
|
||||||
|
ev.viaContactSync = options.viaContactSync;
|
||||||
this.dispatchEvent(ev);
|
this.dispatchEvent(ev);
|
||||||
},
|
},
|
||||||
handleRead: function(read, timestamp) {
|
handleRead: function(read, timestamp) {
|
||||||
|
@ -38526,7 +38530,7 @@ MessageReceiver.prototype.extend({
|
||||||
eventTarget.dispatchEvent(ev);
|
eventTarget.dispatchEvent(ev);
|
||||||
|
|
||||||
if (contactDetails.verified) {
|
if (contactDetails.verified) {
|
||||||
this.handleVerified(contactDetails.verified);
|
this.handleVerified(contactDetails.verified, {viaContactSync: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
contactDetails = contactBuffer.next();
|
contactDetails = contactBuffer.next();
|
||||||
|
|
|
@ -82,23 +82,29 @@
|
||||||
},
|
},
|
||||||
setVerifiedDefault: function(options) {
|
setVerifiedDefault: function(options) {
|
||||||
var DEFAULT = this.verifiedEnum.DEFAULT;
|
var DEFAULT = this.verifiedEnum.DEFAULT;
|
||||||
return this._setVerified(DEFAULT, options);
|
return this.queueJob(function() {
|
||||||
|
return this._setVerified(DEFAULT, options);
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
setVerified: function(options) {
|
setVerified: function(options) {
|
||||||
var VERIFIED = this.verifiedEnum.VERIFIED;
|
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) {
|
_setVerified: function(verified, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
_.defaults(options, {viaSyncMessage: false, key: null});
|
_.defaults(options, {viaSyncMessage: false, viaContactSync: false, key: null});
|
||||||
|
|
||||||
var VERIFIED = this.verifiedEnum.VERIFIED;
|
var VERIFIED = this.verifiedEnum.VERIFIED;
|
||||||
|
var DEFAULT = this.verifiedEnum.DEFAULT;
|
||||||
|
|
||||||
if (!this.isPrivate()) {
|
if (!this.isPrivate()) {
|
||||||
throw new Error('You cannot verify a group conversation. ' +
|
throw new Error('You cannot verify a group conversation. ' +
|
||||||
'You must verify individual contacts.');
|
'You must verify individual contacts.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var beginningVerified = this.get('verified');
|
||||||
var promise;
|
var promise;
|
||||||
if (options.viaSyncMessage) {
|
if (options.viaSyncMessage) {
|
||||||
// handle the incoming key from the sync messages - need different
|
// 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});
|
return this.save({verified: verified});
|
||||||
}.bind(this)).then(function() {
|
}.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) {
|
if (!options.viaSyncMessage) {
|
||||||
return this.sendVerifySyncMessage(this.id, verified);
|
return this.sendVerifySyncMessage(this.id, verified);
|
||||||
}
|
}
|
||||||
|
|
|
@ -625,9 +625,12 @@
|
||||||
timestamp : Date.now(),
|
timestamp : Date.now(),
|
||||||
nonblockingApproval : true
|
nonblockingApproval : true
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
if (!isPresent || !isEqual) {
|
if (isPresent && !isEqual) {
|
||||||
this.trigger('keychange', identifier);
|
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();
|
return resolve();
|
||||||
|
|
|
@ -284,13 +284,17 @@ MessageReceiver.prototype.extend({
|
||||||
throw new Error('Got empty SyncMessage');
|
throw new Error('Got empty SyncMessage');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleVerified: function(verified) {
|
handleVerified: function(verified, options) {
|
||||||
|
options = options || {};
|
||||||
|
_.defaults(options, {viaContactSync: false});
|
||||||
|
|
||||||
var ev = new Event('verified');
|
var ev = new Event('verified');
|
||||||
ev.verified = {
|
ev.verified = {
|
||||||
state: verified.state,
|
state: verified.state,
|
||||||
destination: verified.destination,
|
destination: verified.destination,
|
||||||
identityKey: verified.identityKey.toArrayBuffer()
|
identityKey: verified.identityKey.toArrayBuffer()
|
||||||
};
|
};
|
||||||
|
ev.viaContactSync = options.viaContactSync;
|
||||||
this.dispatchEvent(ev);
|
this.dispatchEvent(ev);
|
||||||
},
|
},
|
||||||
handleRead: function(read, timestamp) {
|
handleRead: function(read, timestamp) {
|
||||||
|
@ -317,7 +321,7 @@ MessageReceiver.prototype.extend({
|
||||||
eventTarget.dispatchEvent(ev);
|
eventTarget.dispatchEvent(ev);
|
||||||
|
|
||||||
if (contactDetails.verified) {
|
if (contactDetails.verified) {
|
||||||
this.handleVerified(contactDetails.verified);
|
this.handleVerified(contactDetails.verified, {viaContactSync: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
contactDetails = contactBuffer.next();
|
contactDetails = contactBuffer.next();
|
||||||
|
|
|
@ -442,7 +442,7 @@ describe("SignalProtocolStore", function() {
|
||||||
).then(fetchRecord).then(function() {
|
).then(fetchRecord).then(function() {
|
||||||
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
|
||||||
assertEqualArrayBuffers(record.get('publicKey'), newIdentity);
|
assertEqualArrayBuffers(record.get('publicKey'), newIdentity);
|
||||||
assert.strictEqual(keychangeTriggered, 1);
|
assert.strictEqual(keychangeTriggered, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue