Move device storage methods to outgoing message
This is the only place they are called. // FREEBIE
This commit is contained in:
parent
daae664965
commit
58452066aa
4 changed files with 66 additions and 82 deletions
|
@ -45,7 +45,6 @@ module.exports = function(grunt) {
|
||||||
'libtextsecure/crypto.js',
|
'libtextsecure/crypto.js',
|
||||||
'libtextsecure/storage.js',
|
'libtextsecure/storage.js',
|
||||||
'libtextsecure/storage/user.js',
|
'libtextsecure/storage/user.js',
|
||||||
'libtextsecure/storage/devices.js',
|
|
||||||
'libtextsecure/storage/groups.js',
|
'libtextsecure/storage/groups.js',
|
||||||
'libtextsecure/protobufs.js',
|
'libtextsecure/protobufs.js',
|
||||||
'libtextsecure/websocket-resources.js',
|
'libtextsecure/websocket-resources.js',
|
||||||
|
|
|
@ -36810,53 +36810,6 @@ Internal.SessionLock.queueJobForNumber = function queueJobForNumber(number, runJ
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
;(function() {
|
|
||||||
/**********************
|
|
||||||
*** Device Storage ***
|
|
||||||
**********************/
|
|
||||||
window.textsecure = window.textsecure || {};
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vim: ts=4:sw=4:expandtab
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
;(function() {
|
;(function() {
|
||||||
/*********************
|
/*********************
|
||||||
*** Group Storage ***
|
*** Group Storage ***
|
||||||
|
@ -38630,7 +38583,7 @@ OutgoingMessage.prototype = {
|
||||||
|
|
||||||
var p;
|
var p;
|
||||||
if (error.code == 409) {
|
if (error.code == 409) {
|
||||||
p = textsecure.storage.devices.removeDeviceIdsForNumber(number, error.response.extraDevices);
|
p = this.removeDeviceIdsForNumber(number, error.response.extraDevices);
|
||||||
} else {
|
} else {
|
||||||
p = Promise.all(error.response.staleDevices.map(function(deviceId) {
|
p = Promise.all(error.response.staleDevices.map(function(deviceId) {
|
||||||
return ciphers[deviceId].closeOpenSessionForDevice();
|
return ciphers[deviceId].closeOpenSessionForDevice();
|
||||||
|
@ -38677,8 +38630,39 @@ OutgoingMessage.prototype = {
|
||||||
return json;
|
return json;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
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;
|
||||||
|
},
|
||||||
|
|
||||||
sendToNumber: function(number) {
|
sendToNumber: function(number) {
|
||||||
return textsecure.storage.devices.getStaleDeviceIdsForNumber(number).then(function(updateDevices) {
|
return this.getStaleDeviceIdsForNumber(number).then(function(updateDevices) {
|
||||||
return this.getKeysForNumber(number, updateDevices)
|
return this.getKeysForNumber(number, updateDevices)
|
||||||
.then(this.reloadDevicesAndSend(number, true))
|
.then(this.reloadDevicesAndSend(number, true))
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
|
|
|
@ -109,7 +109,7 @@ OutgoingMessage.prototype = {
|
||||||
|
|
||||||
var p;
|
var p;
|
||||||
if (error.code == 409) {
|
if (error.code == 409) {
|
||||||
p = textsecure.storage.devices.removeDeviceIdsForNumber(number, error.response.extraDevices);
|
p = this.removeDeviceIdsForNumber(number, error.response.extraDevices);
|
||||||
} else {
|
} else {
|
||||||
p = Promise.all(error.response.staleDevices.map(function(deviceId) {
|
p = Promise.all(error.response.staleDevices.map(function(deviceId) {
|
||||||
return ciphers[deviceId].closeOpenSessionForDevice();
|
return ciphers[deviceId].closeOpenSessionForDevice();
|
||||||
|
@ -156,8 +156,39 @@ OutgoingMessage.prototype = {
|
||||||
return json;
|
return json;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
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;
|
||||||
|
},
|
||||||
|
|
||||||
sendToNumber: function(number) {
|
sendToNumber: function(number) {
|
||||||
return textsecure.storage.devices.getStaleDeviceIdsForNumber(number).then(function(updateDevices) {
|
return this.getStaleDeviceIdsForNumber(number).then(function(updateDevices) {
|
||||||
return this.getKeysForNumber(number, updateDevices)
|
return this.getKeysForNumber(number, updateDevices)
|
||||||
.then(this.reloadDevicesAndSend(number, true))
|
.then(this.reloadDevicesAndSend(number, true))
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
|
|
|
@ -12,35 +12,5 @@
|
||||||
window.textsecure.storage = window.textsecure.storage || {};
|
window.textsecure.storage = window.textsecure.storage || {};
|
||||||
|
|
||||||
window.textsecure.storage.devices = {
|
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue