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('group', onGroupReceived);
|
||||||
messageReceiver.addEventListener('sent', onSentMessage);
|
messageReceiver.addEventListener('sent', onSentMessage);
|
||||||
messageReceiver.addEventListener('read', onReadReceipt);
|
messageReceiver.addEventListener('read', onReadReceipt);
|
||||||
|
// messageReceiver.addEventListener('verify', onVerify);
|
||||||
messageReceiver.addEventListener('error', onError);
|
messageReceiver.addEventListener('error', onError);
|
||||||
|
|
||||||
|
|
||||||
window.textsecure.messaging = new textsecure.MessageSender(
|
window.textsecure.messaging = new textsecure.MessageSender(
|
||||||
SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD
|
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) {
|
function onDeliveryReceipt(ev) {
|
||||||
var pushMessage = ev.proto;
|
var pushMessage = ev.proto;
|
||||||
var timestamp = pushMessage.timestamp.toNumber();
|
var timestamp = pushMessage.timestamp.toNumber();
|
||||||
|
|
|
@ -84,10 +84,9 @@
|
||||||
}.bind(this)).then(this.onMemberVerifiedChange.bind(this));
|
}.bind(this)).then(this.onMemberVerifiedChange.bind(this));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setVerifiedDefault: function() {
|
setVerifiedDefault: function(options) {
|
||||||
function updateTrustStore() {
|
options = options || {};
|
||||||
return Promise.resolve();
|
_.defaults(options, {viaSyncMessage: false, key: null});
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.isPrivate()) {
|
if (!this.isPrivate()) {
|
||||||
throw new Error('You cannot verify a group conversation. ' +
|
throw new Error('You cannot verify a group conversation. ' +
|
||||||
|
@ -95,18 +94,23 @@
|
||||||
}
|
}
|
||||||
var DEFAULT = this.verifiedEnum.DEFAULT;
|
var DEFAULT = this.verifiedEnum.DEFAULT;
|
||||||
|
|
||||||
// return textsecure.storage.protocol.setVerified(this.id, DEFAULT).then(function() {
|
// return textsecure.storage.protocol.setVerified(this.id, DEFAULT, options.key).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() {
|
|
||||||
function updateTrustStore() {
|
function updateTrustStore() {
|
||||||
return Promise.resolve();
|
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;
|
var VERIFIED = this.verifiedEnum.VERIFIED;
|
||||||
|
|
||||||
if (!this.isPrivate()) {
|
if (!this.isPrivate()) {
|
||||||
|
@ -114,14 +118,24 @@
|
||||||
'You must verify individual contacts.');
|
'You must verify individual contacts.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// return textsecure.storage.protocol.setVerified(this.id, VERIFIED).then(function() {
|
// return textsecure.storage.protocol.setVerified(this.id, VERIFIED, options.key).then(function() {
|
||||||
return updateTrustStore(this.id, VERIFIED).then(function() {
|
function updateTrustStore() {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
return updateTrustStore(this.id, VERIFIED, options.key).then(function() {
|
||||||
return this.save({verified: VERIFIED});
|
return this.save({verified: VERIFIED});
|
||||||
}.bind(this)).then(function() {
|
}.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);
|
this.addVerifiedChange(this.id, true);
|
||||||
|
if (!options.viaSyncMessage) {
|
||||||
|
this.sendVerifySyncMessage(this.id, VERIFIED);
|
||||||
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
sendVerifySyncMessage: function(number, state) {
|
||||||
|
// textsecure.storage.protocol.loadIdentityKey(number).then(function(key) {
|
||||||
|
// textsecure.storage.protocol.sendVerifySync(number, state, key);
|
||||||
|
// });
|
||||||
|
},
|
||||||
isVerified: function() {
|
isVerified: function() {
|
||||||
if (this.isPrivate()) {
|
if (this.isPrivate()) {
|
||||||
return this.get('verified') === this.verifiedEnum.VERIFIED;
|
return this.get('verified') === this.verifiedEnum.VERIFIED;
|
||||||
|
@ -171,12 +185,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isUntrusted: function() {
|
isUntrusted: function() {
|
||||||
|
if (this.isPrivate()) {
|
||||||
|
// return textsecure.storage.protocol.isUntrusted(this.id);
|
||||||
function getFromTrustStore() {
|
function getFromTrustStore() {
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isPrivate()) {
|
|
||||||
// return textsecure.storage.protocol.isUntrusted(this.id);
|
|
||||||
return getFromTrustStore(this.id);
|
return getFromTrustStore(this.id);
|
||||||
} else {
|
} else {
|
||||||
if (!this.contactCollection.length) {
|
if (!this.contactCollection.length) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue