Move device storage methods to outgoing message

This is the only place they are called.

// FREEBIE
This commit is contained in:
lilia 2016-05-03 23:31:29 -07:00
parent daae664965
commit 58452066aa
4 changed files with 66 additions and 82 deletions

View file

@ -12,35 +12,5 @@
window.textsecure.storage = window.textsecure.storage || {};
window.textsecure.storage.devices = {
getStaleDeviceIdsForNumber: function(number) {
return textsecure.storage.protocol.getDeviceIds(number).then(function(deviceIds) {
if (deviceIds.length === 0) {
return [1];
}
var updateDevices = [];
return Promise.all(deviceIds.map(function(deviceId) {
var address = new libsignal.SignalProtocolAddress(number, deviceId);
var sessionCipher = new libsignal.SessionCipher(textsecure.storage.protocol, address);
return sessionCipher.hasOpenSession().then(function(hasSession) {
if (!hasSession) {
updateDevices.push(deviceId);
}
});
})).then(function() {
return updateDevices;
});
});
},
removeDeviceIdsForNumber: function(number, deviceIdsToRemove) {
var promise = Promise.resolve();
for (var j in deviceIdsToRemove) {
promise = promise.then(function() {
var encodedNumber = number + "." + deviceIdsToRemove[j];
return textsecure.storage.protocol.removeSession(encodedNumber);
});
}
return promise;
}
};
})();