From 3e648b0ea0a58962157730bc3bd4dcc0a3bfc7df Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 20 Jan 2015 19:48:27 -1000 Subject: [PATCH] Move groups storage back to libtextsecure --- Gruntfile.js | 2 +- libtextsecure/axolotl_wrapper.js | 6 ------ .../storage/groups.js | 20 +++++++------------ 3 files changed, 8 insertions(+), 20 deletions(-) rename libaxolotl/groups_storage.js => libtextsecure/storage/groups.js (92%) diff --git a/Gruntfile.js b/Gruntfile.js index 0aa4f52e..32805b39 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -78,7 +78,6 @@ module.exports = function(grunt) { 'libaxolotl/webcrypto_concat.js', 'libaxolotl/components.js', - 'libaxolotl/groups_storage.js', 'libaxolotl/crypto.js', 'libaxolotl/protocol.js', 'libaxolotl/protobufs.js', @@ -95,6 +94,7 @@ module.exports = function(grunt) { 'libtextsecure/crypto.js', 'libtextsecure/storage.js', 'libtextsecure/storage/devices.js', + 'libtextsecure/storage/groups.js', 'libtextsecure/protobufs.js', 'libtextsecure/websocket.js', 'libtextsecure/websocket-resources.js', diff --git a/libtextsecure/axolotl_wrapper.js b/libtextsecure/axolotl_wrapper.js index 09cdf5ee..ad3c6de9 100644 --- a/libtextsecure/axolotl_wrapper.js +++ b/libtextsecure/axolotl_wrapper.js @@ -5,15 +5,9 @@ ;(function() { window.axolotl = window.axolotl || {}; window.axolotl.api = { - getMyIdentifier: function() { - return textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]; - }, getMyRegistrationId: function() { return textsecure.storage.getUnencrypted("registrationId"); }, - isIdentifierSane: function(identifier) { - return textsecure.utils.isNumberSane(identifier); - }, storage: { put: function(key, value) { return textsecure.storage.putEncrypted(key, value); diff --git a/libaxolotl/groups_storage.js b/libtextsecure/storage/groups.js similarity index 92% rename from libaxolotl/groups_storage.js rename to libtextsecure/storage/groups.js index 5dc0e955..28bdb038 100644 --- a/libaxolotl/groups_storage.js +++ b/libtextsecure/storage/groups.js @@ -20,10 +20,10 @@ /********************* *** Group Storage *** *********************/ - window.axolotl = window.axolotl || {}; - window.axolotl.storage = window.axolotl.storage || {}; + window.textsecure = window.textsecure || {}; + window.textsecure.storage = window.textsecure.storage || {}; - window.axolotl.storage.groups = { + window.textsecure.storage.groups = { createNewGroup: function(numbers, groupId) { if (groupId !== undefined && axolotl.api.storage.get("group" + groupId) !== undefined) throw new Error("Tried to recreate group"); @@ -31,12 +31,12 @@ while (groupId === undefined || axolotl.api.storage.get("group" + groupId) !== undefined) groupId = getString(axolotl.crypto.getRandomBytes(16)); - var me = axolotl.api.getMyIdentifier(); + var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]; var haveMe = false; var finalNumbers = []; for (var i in numbers) { var number = numbers[i]; - if (!axolotl.api.isIdentifierSane(number)) + if (!textsecure.utils.isNumberSane(number)) throw new Error("Invalid number in group"); if (number == me) haveMe = true; @@ -69,7 +69,7 @@ if (group === undefined) return undefined; - var me = axolotl.api.getMyIdentifier(); + var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]; if (number == me) throw new Error("Cannot remove ourselves from a group, leave the group instead"); @@ -90,7 +90,7 @@ for (var i in numbers) { var number = numbers[i]; - if (!axolotl.api.isIdentifierSane(number)) + if (!textsecure.utils.isNumberSane(number)) throw new Error("Invalid number in set to add to group"); if (group.numbers.indexOf(number) < 0) { group.numbers.push(number); @@ -131,10 +131,4 @@ return needUpdate; }, }; - - //TODO: RM - window.textsecure = window.textsecure || {}; - window.textsecure.storage = window.textsecure.storage || {}; - window.textsecure.storage.groups = window.axolotl.storage.groups; - })();