Move session-storage logic to storage/devices from axolotl_wrapper
This commit is contained in:
parent
169097a409
commit
6c0f3ff1f0
3 changed files with 48 additions and 30 deletions
|
@ -37726,23 +37726,10 @@ window.axolotl.sessions = {
|
||||||
|
|
||||||
sessions: {
|
sessions: {
|
||||||
get: function(identifier) {
|
get: function(identifier) {
|
||||||
var device = textsecure.storage.devices.getDeviceObject(identifier, true);
|
return textsecure.storage.sessions.getSessionsForNumber(identifier);
|
||||||
if (device === undefined || device.sessions === undefined)
|
|
||||||
return undefined;
|
|
||||||
return device.sessions;
|
|
||||||
},
|
},
|
||||||
put: function(identifier, record) {
|
put: function(identifier, record) {
|
||||||
var device = textsecure.storage.devices.getDeviceObject(identifier);
|
return textsecure.storage.sessions.putSessionsForDevice(identifier, record);
|
||||||
if (device === undefined) {
|
|
||||||
device = { encodedNumber: identifier,
|
|
||||||
//TODO: Remove this duplication
|
|
||||||
identityKey: record.identityKey
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (getString(device.identityKey) !== getString(record.identityKey))
|
|
||||||
throw new Error("Tried to put session for device with changed identity key");
|
|
||||||
device.sessions = record;
|
|
||||||
return textsecure.storage.devices.saveDeviceObject(device);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -38065,6 +38052,28 @@ window.axolotl.sessions = {
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
window.textsecure.storage = window.textsecure.storage || {};
|
window.textsecure.storage = window.textsecure.storage || {};
|
||||||
|
|
||||||
|
window.textsecure.storage.sessions = {
|
||||||
|
getSessionsForNumber: function(encodedNumber) {
|
||||||
|
var device = textsecure.storage.devices.getDeviceObject(encodedNumber, true);
|
||||||
|
if (device === undefined || device.sessions === undefined)
|
||||||
|
return undefined;
|
||||||
|
return device.sessions;
|
||||||
|
},
|
||||||
|
putSessionsForDevice: function(encodedNumber, sessions) {
|
||||||
|
var device = textsecure.storage.devices.getDeviceObject(encodedNumber);
|
||||||
|
if (device === undefined) {
|
||||||
|
device = { encodedNumber: encodedNumber,
|
||||||
|
//TODO: Remove this duplication
|
||||||
|
identityKey: sessions.identityKey
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (getString(device.identityKey) !== getString(sessions.identityKey))
|
||||||
|
throw new Error("Tried to put session for device with changed identity key");
|
||||||
|
device.sessions = sessions;
|
||||||
|
return textsecure.storage.devices.saveDeviceObject(device);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
window.textsecure.storage.devices = {
|
window.textsecure.storage.devices = {
|
||||||
saveDeviceObject: function(deviceObject) {
|
saveDeviceObject: function(deviceObject) {
|
||||||
return internalSaveDeviceObject(deviceObject, false);
|
return internalSaveDeviceObject(deviceObject, false);
|
||||||
|
|
|
@ -26,23 +26,10 @@
|
||||||
|
|
||||||
sessions: {
|
sessions: {
|
||||||
get: function(identifier) {
|
get: function(identifier) {
|
||||||
var device = textsecure.storage.devices.getDeviceObject(identifier, true);
|
return textsecure.storage.sessions.getSessionsForNumber(identifier);
|
||||||
if (device === undefined || device.sessions === undefined)
|
|
||||||
return undefined;
|
|
||||||
return device.sessions;
|
|
||||||
},
|
},
|
||||||
put: function(identifier, record) {
|
put: function(identifier, record) {
|
||||||
var device = textsecure.storage.devices.getDeviceObject(identifier);
|
return textsecure.storage.sessions.putSessionsForDevice(identifier, record);
|
||||||
if (device === undefined) {
|
|
||||||
device = { encodedNumber: identifier,
|
|
||||||
//TODO: Remove this duplication
|
|
||||||
identityKey: record.identityKey
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (getString(device.identityKey) !== getString(record.identityKey))
|
|
||||||
throw new Error("Tried to put session for device with changed identity key");
|
|
||||||
device.sessions = record;
|
|
||||||
return textsecure.storage.devices.saveDeviceObject(device);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,6 +23,28 @@
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
window.textsecure.storage = window.textsecure.storage || {};
|
window.textsecure.storage = window.textsecure.storage || {};
|
||||||
|
|
||||||
|
window.textsecure.storage.sessions = {
|
||||||
|
getSessionsForNumber: function(encodedNumber) {
|
||||||
|
var device = textsecure.storage.devices.getDeviceObject(encodedNumber, true);
|
||||||
|
if (device === undefined || device.sessions === undefined)
|
||||||
|
return undefined;
|
||||||
|
return device.sessions;
|
||||||
|
},
|
||||||
|
putSessionsForDevice: function(encodedNumber, sessions) {
|
||||||
|
var device = textsecure.storage.devices.getDeviceObject(encodedNumber);
|
||||||
|
if (device === undefined) {
|
||||||
|
device = { encodedNumber: encodedNumber,
|
||||||
|
//TODO: Remove this duplication
|
||||||
|
identityKey: sessions.identityKey
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (getString(device.identityKey) !== getString(sessions.identityKey))
|
||||||
|
throw new Error("Tried to put session for device with changed identity key");
|
||||||
|
device.sessions = sessions;
|
||||||
|
return textsecure.storage.devices.saveDeviceObject(device);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
window.textsecure.storage.devices = {
|
window.textsecure.storage.devices = {
|
||||||
saveDeviceObject: function(deviceObject) {
|
saveDeviceObject: function(deviceObject) {
|
||||||
return internalSaveDeviceObject(deviceObject, false);
|
return internalSaveDeviceObject(deviceObject, false);
|
||||||
|
|
Loading…
Reference in a new issue