From 6c0f3ff1f019a5c71803250884c7ccd7f8ff16e9 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 24 Mar 2015 17:00:01 -0700 Subject: [PATCH] Move session-storage logic to storage/devices from axolotl_wrapper --- js/libtextsecure.js | 39 ++++++++++++++++++++------------ libtextsecure/axolotl_wrapper.js | 17 ++------------ libtextsecure/storage/devices.js | 22 ++++++++++++++++++ 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 8e854275b..8b18671d9 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -37726,23 +37726,10 @@ window.axolotl.sessions = { sessions: { get: function(identifier) { - var device = textsecure.storage.devices.getDeviceObject(identifier, true); - if (device === undefined || device.sessions === undefined) - return undefined; - return device.sessions; + return textsecure.storage.sessions.getSessionsForNumber(identifier); }, put: function(identifier, record) { - var device = textsecure.storage.devices.getDeviceObject(identifier); - 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); + return textsecure.storage.sessions.putSessionsForDevice(identifier, record); } } }, @@ -38065,6 +38052,28 @@ window.axolotl.sessions = { window.textsecure = window.textsecure || {}; 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 = { saveDeviceObject: function(deviceObject) { return internalSaveDeviceObject(deviceObject, false); diff --git a/libtextsecure/axolotl_wrapper.js b/libtextsecure/axolotl_wrapper.js index b04796e03..ae3283032 100644 --- a/libtextsecure/axolotl_wrapper.js +++ b/libtextsecure/axolotl_wrapper.js @@ -26,23 +26,10 @@ sessions: { get: function(identifier) { - var device = textsecure.storage.devices.getDeviceObject(identifier, true); - if (device === undefined || device.sessions === undefined) - return undefined; - return device.sessions; + return textsecure.storage.sessions.getSessionsForNumber(identifier); }, put: function(identifier, record) { - var device = textsecure.storage.devices.getDeviceObject(identifier); - 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); + return textsecure.storage.sessions.putSessionsForDevice(identifier, record); } } }, diff --git a/libtextsecure/storage/devices.js b/libtextsecure/storage/devices.js index 3c2c29e0c..a4e29be20 100644 --- a/libtextsecure/storage/devices.js +++ b/libtextsecure/storage/devices.js @@ -23,6 +23,28 @@ window.textsecure = window.textsecure || {}; 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 = { saveDeviceObject: function(deviceObject) { return internalSaveDeviceObject(deviceObject, false);