Check for device keys in memory before requesting more
// FREEBIE
This commit is contained in:
parent
2b9d039837
commit
b18cfd75de
3 changed files with 22 additions and 4 deletions
|
@ -38140,6 +38140,15 @@ axolotlInternal.RecipientRecord = function() {
|
||||||
delete tempKeys[encodedNumber];
|
delete tempKeys[encodedNumber];
|
||||||
return Promise.resolve();
|
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) {
|
getDeviceObjectsForNumber: function(number) {
|
||||||
return textsecure.storage.axolotl.getIdentityKey(number).then(function(identityKey) {
|
return textsecure.storage.axolotl.getIdentityKey(number).then(function(identityKey) {
|
||||||
|
@ -39805,8 +39814,8 @@ OutgoingMessage.prototype = {
|
||||||
sendToNumber: function(number) {
|
sendToNumber: function(number) {
|
||||||
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) {
|
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) {
|
||||||
return Promise.all(devicesForNumber.map(function(device) {
|
return Promise.all(devicesForNumber.map(function(device) {
|
||||||
return textsecure.protocol_wrapper.hasOpenSession(device.encodedNumber).then(function(result) {
|
return textsecure.storage.devices.needKeysForDevice(device.encodedNumber).then(function(result) {
|
||||||
if (!result) {
|
if (result) {
|
||||||
return this.getKeysForNumber(number,
|
return this.getKeysForNumber(number,
|
||||||
[parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])]
|
[parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])]
|
||||||
).catch(function(error) {
|
).catch(function(error) {
|
||||||
|
|
|
@ -116,8 +116,8 @@ OutgoingMessage.prototype = {
|
||||||
sendToNumber: function(number) {
|
sendToNumber: function(number) {
|
||||||
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) {
|
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devicesForNumber) {
|
||||||
return Promise.all(devicesForNumber.map(function(device) {
|
return Promise.all(devicesForNumber.map(function(device) {
|
||||||
return textsecure.protocol_wrapper.hasOpenSession(device.encodedNumber).then(function(result) {
|
return textsecure.storage.devices.needKeysForDevice(device.encodedNumber).then(function(result) {
|
||||||
if (!result) {
|
if (result) {
|
||||||
return this.getKeysForNumber(number,
|
return this.getKeysForNumber(number,
|
||||||
[parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])]
|
[parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])]
|
||||||
).catch(function(error) {
|
).catch(function(error) {
|
||||||
|
|
|
@ -40,6 +40,15 @@
|
||||||
delete tempKeys[encodedNumber];
|
delete tempKeys[encodedNumber];
|
||||||
return Promise.resolve();
|
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) {
|
getDeviceObjectsForNumber: function(number) {
|
||||||
return textsecure.storage.axolotl.getIdentityKey(number).then(function(identityKey) {
|
return textsecure.storage.axolotl.getIdentityKey(number).then(function(identityKey) {
|
||||||
|
|
Loading…
Reference in a new issue