Check for device keys in memory before requesting more

// FREEBIE
This commit is contained in:
lilia 2015-11-02 11:25:38 -08:00
parent 2b9d039837
commit b18cfd75de
3 changed files with 22 additions and 4 deletions

View file

@ -38140,6 +38140,15 @@ axolotlInternal.RecipientRecord = function() {
delete tempKeys[encodedNumber];
return Promise.resolve();
},
needKeysForDevice: function(encodedNumber) {
if (tempKeys[encodedNumber] !== undefined) {
return Promise.resolve(false);
} else {
return textsecure.protocol_wrapper.hasOpenSession(encodedNumber).then(function(result) {
return !result;
});
}
},
getDeviceObjectsForNumber: function(number) {
return textsecure.storage.axolotl.getIdentityKey(number).then(function(identityKey) {
@ -39805,8 +39814,8 @@ OutgoingMessage.prototype = {
sendToNumber: function(number) {
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) {
return Promise.all(devicesForNumber.map(function(device) {
return textsecure.protocol_wrapper.hasOpenSession(device.encodedNumber).then(function(result) {
if (!result) {
return textsecure.storage.devices.needKeysForDevice(device.encodedNumber).then(function(result) {
if (result) {
return this.getKeysForNumber(number,
[parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])]
).catch(function(error) {

View file

@ -116,8 +116,8 @@ OutgoingMessage.prototype = {
sendToNumber: function(number) {
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) {
return Promise.all(devicesForNumber.map(function(device) {
return textsecure.protocol_wrapper.hasOpenSession(device.encodedNumber).then(function(result) {
if (!result) {
return textsecure.storage.devices.needKeysForDevice(device.encodedNumber).then(function(result) {
if (result) {
return this.getKeysForNumber(number,
[parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])]
).catch(function(error) {

View file

@ -40,6 +40,15 @@
delete tempKeys[encodedNumber];
return Promise.resolve();
},
needKeysForDevice: function(encodedNumber) {
if (tempKeys[encodedNumber] !== undefined) {
return Promise.resolve(false);
} else {
return textsecure.protocol_wrapper.hasOpenSession(encodedNumber).then(function(result) {
return !result;
});
}
},
getDeviceObjectsForNumber: function(number) {
return textsecure.storage.axolotl.getIdentityKey(number).then(function(identityKey) {