Support for sending and receiving verification sync messages

This adds a new method to message sender for sending verification sync messages
and a new event to message receiver representing incoming verification sync
messages. Currently the event handler just logs the message.

// FREEBIE
This commit is contained in:
lilia 2017-06-15 15:00:04 -07:00 committed by Scott Nonnenberg
parent 475d607fd0
commit 52481d1d13
4 changed files with 88 additions and 1 deletions

View file

@ -119,7 +119,7 @@
messageReceiver.addEventListener('group', onGroupReceived);
messageReceiver.addEventListener('sent', onSentMessage);
messageReceiver.addEventListener('read', onReadReceipt);
// messageReceiver.addEventListener('verify', onVerify);
messageReceiver.addEventListener('verification', onVerify);
messageReceiver.addEventListener('error', onError);
@ -326,6 +326,29 @@
});
}
function onVerification(ev) {
var 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;
}
console.log('got verification sync for', ev.destination, state);
/* TODO
processVerifiedMessage(
textsecure.storage.protocol.VerifiedStatus[state],
ev.destination,
ev.identityKey
);
*/
}
window.owsDesktopApp = {
getAppView: function(destWindow) {

View file

@ -38481,10 +38481,23 @@ MessageReceiver.prototype.extend({
console.log('read messages',
'from', envelope.source + '.' + envelope.sourceDevice);
this.handleRead(syncMessage.read, envelope.timestamp);
} else if (syncMessage.verification) {
this.handleVerification(syncMessage.verification);
} else {
throw new Error('Got empty SyncMessage');
}
},
handleVerification: function(verification) {
for (var i = 0; i < verification.length; ++i) {
var ev = new Event('verification');
ev.verification = {
state: verification[i].state,
destination: verification[i].destination,
identityKey: verification[i].identityKey.toArrayBuffer()
};
this.dispatchEvent(ev);
}
},
handleRead: function(read, timestamp) {
for (var i = 0; i < read.length; ++i) {
var ev = new Event('read');
@ -39250,6 +39263,24 @@ MessageSender.prototype = {
return this.sendIndividualProto(myNumber, contentMessage, Date.now());
}
},
syncVerification: function(state, destination, identityKey) {
var myNumber = textsecure.storage.user.getNumber();
var myDevice = textsecure.storage.user.getDeviceId();
if (myDevice != 1) {
var verification = new textsecure.protobuf.SyncMessage.Verification();
verification.state = state;
verification.destination = destination;
verification.identityKey = identityKey;
var syncMessage = new textsecure.protobuf.SyncMessage();
syncMessage.verification = verification;
var contentMessage = new textsecure.protobuf.Content();
contentMessage.syncMessage = syncMessage;
return this.sendIndividualProto(myNumber, contentMessage, Date.now());
}
},
sendGroupProto: function(numbers, proto, timestamp) {
timestamp = timestamp || Date.now();
@ -39495,6 +39526,7 @@ textsecure.MessageSender = function(url, ports, username, password) {
this.sendSyncMessage = sender.sendSyncMessage .bind(sender);
this.getProfile = sender.getProfile .bind(sender);
this.syncReadMessages = sender.syncReadMessages .bind(sender);
this.syncVerification = sender.syncReadMessages .bind(sender);
};
textsecure.MessageSender.prototype = {

View file

@ -272,10 +272,23 @@ MessageReceiver.prototype.extend({
console.log('read messages',
'from', envelope.source + '.' + envelope.sourceDevice);
this.handleRead(syncMessage.read, envelope.timestamp);
} else if (syncMessage.verification) {
this.handleVerification(syncMessage.verification);
} else {
throw new Error('Got empty SyncMessage');
}
},
handleVerification: function(verification) {
for (var i = 0; i < verification.length; ++i) {
var ev = new Event('verification');
ev.verification = {
state: verification[i].state,
destination: verification[i].destination,
identityKey: verification[i].identityKey.toArrayBuffer()
};
this.dispatchEvent(ev);
}
},
handleRead: function(read, timestamp) {
for (var i = 0; i < read.length; ++i) {
var ev = new Event('read');

View file

@ -305,6 +305,24 @@ MessageSender.prototype = {
return this.sendIndividualProto(myNumber, contentMessage, Date.now());
}
},
syncVerification: function(state, destination, identityKey) {
var myNumber = textsecure.storage.user.getNumber();
var myDevice = textsecure.storage.user.getDeviceId();
if (myDevice != 1) {
var verification = new textsecure.protobuf.SyncMessage.Verification();
verification.state = state;
verification.destination = destination;
verification.identityKey = identityKey;
var syncMessage = new textsecure.protobuf.SyncMessage();
syncMessage.verification = verification;
var contentMessage = new textsecure.protobuf.Content();
contentMessage.syncMessage = syncMessage;
return this.sendIndividualProto(myNumber, contentMessage, Date.now());
}
},
sendGroupProto: function(numbers, proto, timestamp) {
timestamp = timestamp || Date.now();
@ -550,6 +568,7 @@ textsecure.MessageSender = function(url, ports, username, password) {
this.sendSyncMessage = sender.sendSyncMessage .bind(sender);
this.getProfile = sender.getProfile .bind(sender);
this.syncReadMessages = sender.syncReadMessages .bind(sender);
this.syncVerification = sender.syncReadMessages .bind(sender);
};
textsecure.MessageSender.prototype = {