Async getSessionsForNumber

This commit is contained in:
lilia 2015-04-09 12:49:47 -07:00
parent 9e7d8c0a08
commit 666f6baaca
4 changed files with 33 additions and 31 deletions

View file

@ -172,9 +172,7 @@
getSession: function(identifier) { getSession: function(identifier) {
if (identifier === null || identifier === undefined) if (identifier === null || identifier === undefined)
throw new Error("Tried to get session for undefined/null key"); throw new Error("Tried to get session for undefined/null key");
return new Promise(function(resolve) { return textsecure.storage.sessions.getSessionsForNumber(identifier);
resolve(textsecure.storage.sessions.getSessionsForNumber(identifier));
});
}, },
putSession: function(identifier, record) { putSession: function(identifier, record) {
if (identifier === null || identifier === undefined) if (identifier === null || identifier === undefined)

View file

@ -38096,6 +38096,7 @@ axolotlInternal.RecipientRecord = function() {
window.textsecure.storage.sessions = { window.textsecure.storage.sessions = {
getSessionsForNumber: function(encodedNumber) { getSessionsForNumber: function(encodedNumber) {
return Promise.resolve((function() {
var number = textsecure.utils.unencodeNumber(encodedNumber)[0]; var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
var deviceId = textsecure.utils.unencodeNumber(encodedNumber)[1]; var deviceId = textsecure.utils.unencodeNumber(encodedNumber)[1];
@ -38106,6 +38107,7 @@ axolotlInternal.RecipientRecord = function() {
return undefined; return undefined;
return sessions[deviceId]; return sessions[deviceId];
})());
}, },
putSessionsForDevice: function(encodedNumber, record) { putSessionsForDevice: function(encodedNumber, record) {
@ -39807,12 +39809,12 @@ window.textsecure.messaging = function() {
var getDevicesAndSendToNumber = function(number) { var getDevicesAndSendToNumber = function(number) {
var devicesForNumber = textsecure.storage.devices.getDeviceObjectsForNumber(number); var devicesForNumber = textsecure.storage.devices.getDeviceObjectsForNumber(number);
var promises = []; return Promise.all(devicesForNumber.map(function(device) {
for (var j in devicesForNumber) return textsecure.protocol_wrapper.hasOpenSession(device.encodedNumber).then(function(result) {
if (!textsecure.protocol_wrapper.hasOpenSession(devicesForNumber[j].encodedNumber)) if (!result)
promises[promises.length] = getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(devicesForNumber[j].encodedNumber)[1])]); return getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])]);
});
Promise.all(promises).then(function() { })).then(function() {
devicesForNumber = textsecure.storage.devices.getDeviceObjectsForNumber(number); devicesForNumber = textsecure.storage.devices.getDeviceObjectsForNumber(number);
if (devicesForNumber.length == 0) { if (devicesForNumber.length == 0) {

View file

@ -210,12 +210,12 @@ window.textsecure.messaging = function() {
var getDevicesAndSendToNumber = function(number) { var getDevicesAndSendToNumber = function(number) {
var devicesForNumber = textsecure.storage.devices.getDeviceObjectsForNumber(number); var devicesForNumber = textsecure.storage.devices.getDeviceObjectsForNumber(number);
var promises = []; return Promise.all(devicesForNumber.map(function(device) {
for (var j in devicesForNumber) return textsecure.protocol_wrapper.hasOpenSession(device.encodedNumber).then(function(result) {
if (!textsecure.protocol_wrapper.hasOpenSession(devicesForNumber[j].encodedNumber)) if (!result)
promises[promises.length] = getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(devicesForNumber[j].encodedNumber)[1])]); return getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(device.encodedNumber)[1])]);
});
Promise.all(promises).then(function() { })).then(function() {
devicesForNumber = textsecure.storage.devices.getDeviceObjectsForNumber(number); devicesForNumber = textsecure.storage.devices.getDeviceObjectsForNumber(number);
if (devicesForNumber.length == 0) { if (devicesForNumber.length == 0) {

View file

@ -25,6 +25,7 @@
window.textsecure.storage.sessions = { window.textsecure.storage.sessions = {
getSessionsForNumber: function(encodedNumber) { getSessionsForNumber: function(encodedNumber) {
return Promise.resolve((function() {
var number = textsecure.utils.unencodeNumber(encodedNumber)[0]; var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
var deviceId = textsecure.utils.unencodeNumber(encodedNumber)[1]; var deviceId = textsecure.utils.unencodeNumber(encodedNumber)[1];
@ -35,6 +36,7 @@
return undefined; return undefined;
return sessions[deviceId]; return sessions[deviceId];
})());
}, },
putSessionsForDevice: function(encodedNumber, record) { putSessionsForDevice: function(encodedNumber, record) {