diff --git a/libtextsecure/axolotl_wrapper.js b/libtextsecure/axolotl_wrapper.js index bfe4a2e8..379fcc96 100644 --- a/libtextsecure/axolotl_wrapper.js +++ b/libtextsecure/axolotl_wrapper.js @@ -39,9 +39,8 @@ var device = textsecure.storage.devices.getDeviceObject(identifier); if (device === undefined) { device = { encodedNumber: identifier, - //TODO: Remove this duplication (esp registrationId?) - identityKey: record.identityKey, - registrationId: record.registrationId + //TODO: Remove this duplication + identityKey: record.identityKey }; } if (getString(device.identityKey) !== getString(record.identityKey)) diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 9d769ccd..53c8540b 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -19,6 +19,7 @@ window.textsecure.messaging = function() { var self = {}; + //TODO: Dont hit disk for any of the key-fetching! function getKeysForNumber(number, updateDevices) { var handleResult = function(response) { for (var i in response.devices) { @@ -68,10 +69,12 @@ window.textsecure.messaging = function() { return axolotl.protocol.encryptMessageFor(deviceObjectList[i], message).then(function(encryptedMsg) { textsecure.storage.devices.removeTempKeysFromDevice(deviceObjectList[i].encodedNumber); + var registrationId = deviceObjectList[i].registrationId || deviceObjectList[i].sessions.registrationId; + jsonData[i] = { type: encryptedMsg.type, destinationDeviceId: textsecure.utils.unencodeNumber(deviceObjectList[i].encodedNumber)[1], - destinationRegistrationId: deviceObjectList[i].registrationId, + destinationRegistrationId: registrationId, body: encryptedMsg.body, timestamp: timestamp }; @@ -94,7 +97,8 @@ window.textsecure.messaging = function() { var doUpdate = false; for (var i in devicesForNumber) { - if (textsecure.storage.groups.needUpdateByDeviceRegistrationId(groupId, number, devicesForNumber[i].encodedNumber, devicesForNumber[i].registrationId)) + var registrationId = devicesForNumber[i].registrationId || devicesForNumber[i].sessions.registrationId; + if (textsecure.storage.groups.needUpdateByDeviceRegistrationId(groupId, number, devicesForNumber[i].encodedNumber, registrationId)) doUpdate = true; } if (!doUpdate) @@ -210,7 +214,7 @@ window.textsecure.messaging = function() { var promises = []; for (var j in devicesForNumber) - if (devicesForNumber[j].registrationId === undefined) + if (devicesForNumber[j].sessions === undefined || !devicesForNumber[j].sessions.haveOpenSession()) promises[promises.length] = getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(devicesForNumber[j].encodedNumber)[1])]); Promise.all(promises).then(function() { diff --git a/libtextsecure/storage/devices.js b/libtextsecure/storage/devices.js index 239e04af..1155253e 100644 --- a/libtextsecure/storage/devices.js +++ b/libtextsecure/storage/devices.js @@ -40,6 +40,7 @@ delete deviceObject['signedKeySignature']; delete deviceObject['preKey']; delete deviceObject['preKeyId']; + delete deviceObject['registrationId']; } catch(_) {} return internalSaveDeviceObject(deviceObject, false); }, @@ -127,7 +128,7 @@ }; var internalSaveDeviceObject = function(deviceObject, onlyKeys) { - if (deviceObject.identityKey === undefined || deviceObject.encodedNumber === undefined || deviceObject.registrationId === undefined) + if (deviceObject.identityKey === undefined || deviceObject.encodedNumber === undefined) throw new Error("Tried to store invalid deviceObject"); var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0];