Prepare for verification sync messages: receiver, ready to send
FREEBIE
This commit is contained in:
parent
aebf4b32d6
commit
475d607fd0
2 changed files with 56 additions and 20 deletions
|
@ -119,8 +119,10 @@
|
|||
messageReceiver.addEventListener('group', onGroupReceived);
|
||||
messageReceiver.addEventListener('sent', onSentMessage);
|
||||
messageReceiver.addEventListener('read', onReadReceipt);
|
||||
// messageReceiver.addEventListener('verify', onVerify);
|
||||
messageReceiver.addEventListener('error', onError);
|
||||
|
||||
|
||||
window.textsecure.messaging = new textsecure.MessageSender(
|
||||
SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD
|
||||
);
|
||||
|
@ -289,6 +291,27 @@
|
|||
});
|
||||
}
|
||||
|
||||
var VERIFIED_ENUM = textsecure.storage.protocol.VerifiedStatus;
|
||||
|
||||
function onVerify(ev) {
|
||||
var number = ev.destination;
|
||||
var key = ev.identityKey;
|
||||
var verified = ev.state;
|
||||
|
||||
console.log('verification sync message', number, verified);
|
||||
|
||||
var contact = ConversationController.get(number);
|
||||
if (!contact) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (verified === VERIFIED_ENUM.DEFAULT) {
|
||||
contact.setVerifiedDefault({viaSyncMessage: true, key: key});
|
||||
} else if (verified === VERIFIED_ENUM.VERIFIED) {
|
||||
contact.setVerified({viaSyncMessage: true, key: key});
|
||||
}
|
||||
}
|
||||
|
||||
function onDeliveryReceipt(ev) {
|
||||
var pushMessage = ev.proto;
|
||||
var timestamp = pushMessage.timestamp.toNumber();
|
||||
|
|
|
@ -84,10 +84,9 @@
|
|||
}.bind(this)).then(this.onMemberVerifiedChange.bind(this));
|
||||
}
|
||||
},
|
||||
setVerifiedDefault: function() {
|
||||
function updateTrustStore() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
setVerifiedDefault: function(options) {
|
||||
options = options || {};
|
||||
_.defaults(options, {viaSyncMessage: false, key: null});
|
||||
|
||||
if (!this.isPrivate()) {
|
||||
throw new Error('You cannot verify a group conversation. ' +
|
||||
|
@ -95,18 +94,23 @@
|
|||
}
|
||||
var DEFAULT = this.verifiedEnum.DEFAULT;
|
||||
|
||||
// return textsecure.storage.protocol.setVerified(this.id, DEFAULT).then(function() {
|
||||
return updateTrustStore(this.id, DEFAULT).then(function() {
|
||||
return this.save({verified: DEFAULT});
|
||||
}.bind(this)).then(function() {
|
||||
// TODO: send sync message? add a parameter to tell us if this is via a sync message?
|
||||
this.addVerifiedChange(this.id, false);
|
||||
}.bind(this));
|
||||
},
|
||||
setVerified: function() {
|
||||
// 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 this.save({verified: DEFAULT});
|
||||
}.bind(this)).then(function() {
|
||||
this.addVerifiedChange(this.id, false);
|
||||
if (!options.viaSyncMessage) {
|
||||
this.sendVerifySyncMessage(this.id, DEFAULT);
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
setVerified: function(options) {
|
||||
options = options || {};
|
||||
_.defaults(options, {viaSyncMessage: false, key: null});
|
||||
|
||||
var VERIFIED = this.verifiedEnum.VERIFIED;
|
||||
|
||||
if (!this.isPrivate()) {
|
||||
|
@ -114,14 +118,24 @@
|
|||
'You must verify individual contacts.');
|
||||
}
|
||||
|
||||
// return textsecure.storage.protocol.setVerified(this.id, VERIFIED).then(function() {
|
||||
return updateTrustStore(this.id, VERIFIED).then(function() {
|
||||
// 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 this.save({verified: VERIFIED});
|
||||
}.bind(this)).then(function() {
|
||||
// TODO: send sync message? add a parameter to tell us if this is via a sync message?
|
||||
this.addVerifiedChange(this.id, true);
|
||||
if (!options.viaSyncMessage) {
|
||||
this.sendVerifySyncMessage(this.id, VERIFIED);
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
sendVerifySyncMessage: function(number, state) {
|
||||
// textsecure.storage.protocol.loadIdentityKey(number).then(function(key) {
|
||||
// textsecure.storage.protocol.sendVerifySync(number, state, key);
|
||||
// });
|
||||
},
|
||||
isVerified: function() {
|
||||
if (this.isPrivate()) {
|
||||
return this.get('verified') === this.verifiedEnum.VERIFIED;
|
||||
|
@ -171,12 +185,11 @@
|
|||
}
|
||||
},
|
||||
isUntrusted: function() {
|
||||
function getFromTrustStore() {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
if (this.isPrivate()) {
|
||||
// return textsecure.storage.protocol.isUntrusted(this.id);
|
||||
function getFromTrustStore() {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
return getFromTrustStore(this.id);
|
||||
} else {
|
||||
if (!this.contactCollection.length) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue