De-duplicate registrationId in deviceObject
This commit is contained in:
parent
92d0de6837
commit
b356403061
3 changed files with 11 additions and 7 deletions
|
@ -39,9 +39,8 @@
|
||||||
var device = textsecure.storage.devices.getDeviceObject(identifier);
|
var device = textsecure.storage.devices.getDeviceObject(identifier);
|
||||||
if (device === undefined) {
|
if (device === undefined) {
|
||||||
device = { encodedNumber: identifier,
|
device = { encodedNumber: identifier,
|
||||||
//TODO: Remove this duplication (esp registrationId?)
|
//TODO: Remove this duplication
|
||||||
identityKey: record.identityKey,
|
identityKey: record.identityKey
|
||||||
registrationId: record.registrationId
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (getString(device.identityKey) !== getString(record.identityKey))
|
if (getString(device.identityKey) !== getString(record.identityKey))
|
||||||
|
|
|
@ -19,6 +19,7 @@ window.textsecure.messaging = function() {
|
||||||
|
|
||||||
var self = {};
|
var self = {};
|
||||||
|
|
||||||
|
//TODO: Dont hit disk for any of the key-fetching!
|
||||||
function getKeysForNumber(number, updateDevices) {
|
function getKeysForNumber(number, updateDevices) {
|
||||||
var handleResult = function(response) {
|
var handleResult = function(response) {
|
||||||
for (var i in response.devices) {
|
for (var i in response.devices) {
|
||||||
|
@ -68,10 +69,12 @@ window.textsecure.messaging = function() {
|
||||||
|
|
||||||
return axolotl.protocol.encryptMessageFor(deviceObjectList[i], message).then(function(encryptedMsg) {
|
return axolotl.protocol.encryptMessageFor(deviceObjectList[i], message).then(function(encryptedMsg) {
|
||||||
textsecure.storage.devices.removeTempKeysFromDevice(deviceObjectList[i].encodedNumber);
|
textsecure.storage.devices.removeTempKeysFromDevice(deviceObjectList[i].encodedNumber);
|
||||||
|
var registrationId = deviceObjectList[i].registrationId || deviceObjectList[i].sessions.registrationId;
|
||||||
|
|
||||||
jsonData[i] = {
|
jsonData[i] = {
|
||||||
type: encryptedMsg.type,
|
type: encryptedMsg.type,
|
||||||
destinationDeviceId: textsecure.utils.unencodeNumber(deviceObjectList[i].encodedNumber)[1],
|
destinationDeviceId: textsecure.utils.unencodeNumber(deviceObjectList[i].encodedNumber)[1],
|
||||||
destinationRegistrationId: deviceObjectList[i].registrationId,
|
destinationRegistrationId: registrationId,
|
||||||
body: encryptedMsg.body,
|
body: encryptedMsg.body,
|
||||||
timestamp: timestamp
|
timestamp: timestamp
|
||||||
};
|
};
|
||||||
|
@ -94,7 +97,8 @@ window.textsecure.messaging = function() {
|
||||||
|
|
||||||
var doUpdate = false;
|
var doUpdate = false;
|
||||||
for (var i in devicesForNumber) {
|
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;
|
doUpdate = true;
|
||||||
}
|
}
|
||||||
if (!doUpdate)
|
if (!doUpdate)
|
||||||
|
@ -210,7 +214,7 @@ window.textsecure.messaging = function() {
|
||||||
|
|
||||||
var promises = [];
|
var promises = [];
|
||||||
for (var j in devicesForNumber)
|
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])]);
|
promises[promises.length] = getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(devicesForNumber[j].encodedNumber)[1])]);
|
||||||
|
|
||||||
Promise.all(promises).then(function() {
|
Promise.all(promises).then(function() {
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
delete deviceObject['signedKeySignature'];
|
delete deviceObject['signedKeySignature'];
|
||||||
delete deviceObject['preKey'];
|
delete deviceObject['preKey'];
|
||||||
delete deviceObject['preKeyId'];
|
delete deviceObject['preKeyId'];
|
||||||
|
delete deviceObject['registrationId'];
|
||||||
} catch(_) {}
|
} catch(_) {}
|
||||||
return internalSaveDeviceObject(deviceObject, false);
|
return internalSaveDeviceObject(deviceObject, false);
|
||||||
},
|
},
|
||||||
|
@ -127,7 +128,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var internalSaveDeviceObject = function(deviceObject, onlyKeys) {
|
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");
|
throw new Error("Tried to store invalid deviceObject");
|
||||||
|
|
||||||
var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0];
|
var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0];
|
||||||
|
|
Loading…
Reference in a new issue