diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 7eb70d366..492ed1698 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -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) { diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 16af122d7..d501409fa 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -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) { diff --git a/libtextsecure/storage/devices.js b/libtextsecure/storage/devices.js index eb16b5cc4..4ba782992 100644 --- a/libtextsecure/storage/devices.js +++ b/libtextsecure/storage/devices.js @@ -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) {