Inline some functions in OutgoingMessage
Since we no longer have legacy messages to send, we can simplify things a bit here. // FREEBIE
This commit is contained in:
parent
ca7fdc91b7
commit
30201969be
2 changed files with 16 additions and 40 deletions
|
@ -38811,7 +38811,14 @@ OutgoingMessage.prototype = {
|
||||||
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
||||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||||
ciphers[address.getDeviceId()] = sessionCipher;
|
ciphers[address.getDeviceId()] = sessionCipher;
|
||||||
return this.encryptToDevice(address, paddedPlaintext, sessionCipher);
|
return sessionCipher.encrypt(paddedPlaintext).then(function(ciphertext) {
|
||||||
|
return {
|
||||||
|
type : ciphertext.type,
|
||||||
|
destinationDeviceId : address.getDeviceId(),
|
||||||
|
destinationRegistrationId : ciphertext.registrationId,
|
||||||
|
content : btoa(ciphertext.body)
|
||||||
|
};
|
||||||
|
});
|
||||||
}.bind(this))).then(function(jsonData) {
|
}.bind(this))).then(function(jsonData) {
|
||||||
return this.transmitMessage(number, jsonData, this.timestamp).then(function() {
|
return this.transmitMessage(number, jsonData, this.timestamp).then(function() {
|
||||||
this.successfulNumbers[this.successfulNumbers.length] = number;
|
this.successfulNumbers[this.successfulNumbers.length] = number;
|
||||||
|
@ -38845,25 +38852,6 @@ OutgoingMessage.prototype = {
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
encryptToDevice: function(address, plaintext, sessionCipher) {
|
|
||||||
return sessionCipher.encrypt(plaintext).then(function(ciphertext) {
|
|
||||||
return this.toJSON(address, ciphertext);
|
|
||||||
}.bind(this));
|
|
||||||
},
|
|
||||||
|
|
||||||
toJSON: function(address, encryptedMsg) {
|
|
||||||
var json = {
|
|
||||||
type : encryptedMsg.type,
|
|
||||||
destinationDeviceId : address.getDeviceId(),
|
|
||||||
destinationRegistrationId : encryptedMsg.registrationId
|
|
||||||
};
|
|
||||||
|
|
||||||
var content = btoa(encryptedMsg.body);
|
|
||||||
json.content = content;
|
|
||||||
|
|
||||||
return json;
|
|
||||||
},
|
|
||||||
|
|
||||||
getStaleDeviceIdsForNumber: function(number) {
|
getStaleDeviceIdsForNumber: function(number) {
|
||||||
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
||||||
if (deviceIds.length === 0) {
|
if (deviceIds.length === 0) {
|
||||||
|
|
|
@ -132,7 +132,14 @@ OutgoingMessage.prototype = {
|
||||||
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
var address = new libsignal.SignalProtocolAddress(number, deviceId);
|
||||||
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
|
||||||
ciphers[address.getDeviceId()] = sessionCipher;
|
ciphers[address.getDeviceId()] = sessionCipher;
|
||||||
return this.encryptToDevice(address, paddedPlaintext, sessionCipher);
|
return sessionCipher.encrypt(paddedPlaintext).then(function(ciphertext) {
|
||||||
|
return {
|
||||||
|
type : ciphertext.type,
|
||||||
|
destinationDeviceId : address.getDeviceId(),
|
||||||
|
destinationRegistrationId : ciphertext.registrationId,
|
||||||
|
content : btoa(ciphertext.body)
|
||||||
|
};
|
||||||
|
});
|
||||||
}.bind(this))).then(function(jsonData) {
|
}.bind(this))).then(function(jsonData) {
|
||||||
return this.transmitMessage(number, jsonData, this.timestamp).then(function() {
|
return this.transmitMessage(number, jsonData, this.timestamp).then(function() {
|
||||||
this.successfulNumbers[this.successfulNumbers.length] = number;
|
this.successfulNumbers[this.successfulNumbers.length] = number;
|
||||||
|
@ -166,25 +173,6 @@ OutgoingMessage.prototype = {
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
encryptToDevice: function(address, plaintext, sessionCipher) {
|
|
||||||
return sessionCipher.encrypt(plaintext).then(function(ciphertext) {
|
|
||||||
return this.toJSON(address, ciphertext);
|
|
||||||
}.bind(this));
|
|
||||||
},
|
|
||||||
|
|
||||||
toJSON: function(address, encryptedMsg) {
|
|
||||||
var json = {
|
|
||||||
type : encryptedMsg.type,
|
|
||||||
destinationDeviceId : address.getDeviceId(),
|
|
||||||
destinationRegistrationId : encryptedMsg.registrationId
|
|
||||||
};
|
|
||||||
|
|
||||||
var content = btoa(encryptedMsg.body);
|
|
||||||
json.content = content;
|
|
||||||
|
|
||||||
return json;
|
|
||||||
},
|
|
||||||
|
|
||||||
getStaleDeviceIdsForNumber: function(number) {
|
getStaleDeviceIdsForNumber: function(number) {
|
||||||
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
|
||||||
if (deviceIds.length === 0) {
|
if (deviceIds.length === 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue