Replace load/decode/index around our own number with helpers
This commit is contained in:
parent
3759fe46e9
commit
454b4726bd
12 changed files with 120 additions and 41 deletions
|
@ -43,6 +43,7 @@ module.exports = function(grunt) {
|
||||||
|
|
||||||
'libtextsecure/crypto.js',
|
'libtextsecure/crypto.js',
|
||||||
'libtextsecure/storage.js',
|
'libtextsecure/storage.js',
|
||||||
|
'libtextsecure/storage/user.js',
|
||||||
'libtextsecure/storage/devices.js',
|
'libtextsecure/storage/devices.js',
|
||||||
'libtextsecure/storage/groups.js',
|
'libtextsecure/storage/groups.js',
|
||||||
'libtextsecure/protobufs.js',
|
'libtextsecure/protobufs.js',
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
var bg = extension.windows.getBackground();
|
var bg = extension.windows.getBackground();
|
||||||
|
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
if (bg.textsecure.storage.getUnencrypted("number_id") === undefined) {
|
if (bg.textsecure.storage.user.getNumber() === undefined) {
|
||||||
window.location = '/options.html';
|
window.location = '/options.html';
|
||||||
} else {
|
} else {
|
||||||
new bg.Whisper.InboxView().$el.prependTo(bg.$('body',document));
|
new bg.Whisper.InboxView().$el.prependTo(bg.$('body',document));
|
||||||
|
|
|
@ -38004,6 +38004,53 @@ window.axolotl.sessions = {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
/* vim: ts=4:sw=4
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
;(function() {
|
||||||
|
/*********************************************
|
||||||
|
*** Utilities to store data about the user ***
|
||||||
|
**********************************************/
|
||||||
|
window.textsecure = window.textsecure || {};
|
||||||
|
window.textsecure.storage = window.textsecure.storage || {};
|
||||||
|
|
||||||
|
window.textsecure.storage.user = {
|
||||||
|
setNumberAndDeviceId: function(number, deviceId) {
|
||||||
|
textsecure.storage.putUnencrypted("number_id", number + "." + deviceId);
|
||||||
|
},
|
||||||
|
|
||||||
|
getNumber: function(key, defaultValue) {
|
||||||
|
var number_id = textsecure.storage.getUnencrypted("number_id");
|
||||||
|
if (number_id === undefined)
|
||||||
|
return undefined;
|
||||||
|
return textsecure.utils.unencodeNumber(number_id)[0];
|
||||||
|
},
|
||||||
|
|
||||||
|
getDeviceId: function(key) {
|
||||||
|
var number_id = textsecure.storage.getUnencrypted("number_id");
|
||||||
|
if (number_id === undefined)
|
||||||
|
return undefined;
|
||||||
|
return textsecure.utils.unencodeNumber(number_id)[1];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
|
||||||
/* vim: ts=4:sw=4
|
/* vim: ts=4:sw=4
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
@ -38213,7 +38260,7 @@ window.axolotl.sessions = {
|
||||||
while (groupId === undefined || textsecure.storage.getEncrypted("group" + groupId) !== undefined)
|
while (groupId === undefined || textsecure.storage.getEncrypted("group" + groupId) !== undefined)
|
||||||
groupId = getString(textsecure.crypto.getRandomBytes(16));
|
groupId = getString(textsecure.crypto.getRandomBytes(16));
|
||||||
|
|
||||||
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
|
var me = textsecure.storage.user.getNumber();
|
||||||
var haveMe = false;
|
var haveMe = false;
|
||||||
var finalNumbers = [];
|
var finalNumbers = [];
|
||||||
for (var i in numbers) {
|
for (var i in numbers) {
|
||||||
|
@ -38251,7 +38298,7 @@ window.axolotl.sessions = {
|
||||||
if (group === undefined)
|
if (group === undefined)
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
||||||
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
|
var me = textsecure.storage.user.getNumber();
|
||||||
if (number == me)
|
if (number == me)
|
||||||
throw new Error("Cannot remove ourselves from a group, leave the group instead");
|
throw new Error("Cannot remove ourselves from a group, leave the group instead");
|
||||||
|
|
||||||
|
@ -38738,7 +38785,7 @@ textsecure.processDecrypted = function(decrypted, source) {
|
||||||
if (decrypted.flags == null)
|
if (decrypted.flags == null)
|
||||||
decrypted.flags = 0;
|
decrypted.flags = 0;
|
||||||
|
|
||||||
if (decrypted.sync !== null && textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0] != source)
|
if (decrypted.sync !== null && textsecure.storage.user.getNumber() != source)
|
||||||
throw new Error("Got sync context on a message not from a peer device");
|
throw new Error("Got sync context on a message not from a peer device");
|
||||||
|
|
||||||
if ((decrypted.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
if ((decrypted.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||||
|
@ -38843,8 +38890,7 @@ window.textsecure.registerSingleDevice = function(number, verificationCode, step
|
||||||
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
||||||
|
|
||||||
return textsecure.api.confirmCode(number, verificationCode, password, signalingKey, registrationId, true).then(function() {
|
return textsecure.api.confirmCode(number, verificationCode, password, signalingKey, registrationId, true).then(function() {
|
||||||
var numberId = number + ".1";
|
textsecure.storage.user.setNumberAndDeviceId(number, 1);
|
||||||
textsecure.storage.putUnencrypted("number_id", numberId);
|
|
||||||
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
|
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
|
||||||
stepDone(1);
|
stepDone(1);
|
||||||
|
|
||||||
|
@ -38874,8 +38920,7 @@ window.textsecure.registerSecondDevice = function(encodedProvisionEnvelope, cryp
|
||||||
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
||||||
|
|
||||||
return textsecure.api.confirmCode(identityKey.number, identityKey.provisioningCode, password, signalingKey, registrationId, false).then(function(result) {
|
return textsecure.api.confirmCode(identityKey.number, identityKey.provisioningCode, password, signalingKey, registrationId, false).then(function(result) {
|
||||||
var numberId = identityKey.number + "." + result.deviceId;
|
textsecure.storage.user.setNumberAndDeviceId(identityKey.number, result.deviceId);
|
||||||
textsecure.storage.putUnencrypted("number_id", numberId);
|
|
||||||
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(identityKey.number));
|
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(identityKey.number));
|
||||||
stepDone(2);
|
stepDone(2);
|
||||||
|
|
||||||
|
@ -39084,7 +39129,7 @@ window.textsecure.api = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param.do_auth) {
|
if (param.do_auth) {
|
||||||
param.user = textsecure.storage.getUnencrypted("number_id");
|
param.user = textsecure.storage.user.getNumber() + "." + textsecure.storage.user.getDeviceId();
|
||||||
param.password = textsecure.storage.getEncrypted("password");
|
param.password = textsecure.storage.getEncrypted("password");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39310,7 +39355,7 @@ window.textsecure.api = function () {
|
||||||
var URL = URL_BASE.replace(/^http/g, 'ws') + url + '/?';
|
var URL = URL_BASE.replace(/^http/g, 'ws') + url + '/?';
|
||||||
var params = '';
|
var params = '';
|
||||||
if (auth) {
|
if (auth) {
|
||||||
var user = textsecure.storage.getUnencrypted("number_id");
|
var user = textsecure.storage.user.getNumber() + "." + textsecure.storage.user.getDeviceId();
|
||||||
var password = textsecure.storage.getEncrypted("password");
|
var password = textsecure.storage.getEncrypted("password");
|
||||||
var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
|
var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
|
||||||
}
|
}
|
||||||
|
@ -39586,9 +39631,8 @@ window.textsecure.messaging = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var sendSyncMessage = function(message, timestamp, destination) {
|
var sendSyncMessage = function(message, timestamp, destination) {
|
||||||
var numberDevice = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"));
|
var myNumber = textsecure.storage.user.getNumber();
|
||||||
var myNumber = numberDevice[0];
|
var myDevice = textsecure.storage.user.getDeviceId();
|
||||||
var myDevice = numberDevice[1];
|
|
||||||
if (myDevice != 1) {
|
if (myDevice != 1) {
|
||||||
var sync_message = textsecure.protobuf.PushMessageContent.decode(message.encode());
|
var sync_message = textsecure.protobuf.PushMessageContent.decode(message.encode());
|
||||||
sync_message.sync = new textsecure.protobuf.PushMessageContent.SyncMessageContext();
|
sync_message.sync = new textsecure.protobuf.PushMessageContent.SyncMessageContext();
|
||||||
|
@ -39600,7 +39644,7 @@ window.textsecure.messaging = function() {
|
||||||
|
|
||||||
var sendGroupProto = function(numbers, proto, timestamp) {
|
var sendGroupProto = function(numbers, proto, timestamp) {
|
||||||
timestamp = timestamp || Date.now();
|
timestamp = timestamp || Date.now();
|
||||||
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
|
var me = textsecure.storage.user.getNumber();
|
||||||
numbers = numbers.filter(function(number) { return number != me; });
|
numbers = numbers.filter(function(number) { return number != me; });
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
|
|
@ -37,11 +37,7 @@
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
if (textsecure.registration.isDone()) {
|
if (textsecure.registration.isDone()) {
|
||||||
$('#complete-number').text(
|
$('#complete-number').text(textsecure.storage.user.getNumber());
|
||||||
textsecure.utils.unencodeNumber(
|
|
||||||
textsecure.storage.getUnencrypted("number_id")
|
|
||||||
)[0]
|
|
||||||
);//TODO: no
|
|
||||||
$('#setup-complete').show().addClass('in');
|
$('#setup-complete').show().addClass('in');
|
||||||
initOptions();
|
initOptions();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -36,9 +36,9 @@
|
||||||
var phoneView = new Whisper.PhoneInputView({el: $('#phone-number-input')});
|
var phoneView = new Whisper.PhoneInputView({el: $('#phone-number-input')});
|
||||||
phoneView.$el.find('input.number').intlTelInput();
|
phoneView.$el.find('input.number').intlTelInput();
|
||||||
|
|
||||||
var number = textsecure.storage.getUnencrypted('number_id');
|
var number = textsecure.storage.user.getNumber();
|
||||||
if (number) {
|
if (number) {
|
||||||
$('input.number').val(number.split('.')[0]);
|
$('input.number').val(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
$('input.number').on('validation', function() {
|
$('input.number').on('validation', function() {
|
||||||
|
@ -98,7 +98,7 @@
|
||||||
textsecure.storage.putUnencrypted('registrationId', registrationId);
|
textsecure.storage.putUnencrypted('registrationId', registrationId);
|
||||||
textsecure.storage.putEncrypted('signaling_key', signalingKey);
|
textsecure.storage.putEncrypted('signaling_key', signalingKey);
|
||||||
textsecure.storage.putEncrypted('password', password);
|
textsecure.storage.putEncrypted('password', password);
|
||||||
textsecure.storage.putUnencrypted('number_id', number + '.1');
|
textsecure.storage.user.setNumberAndDeviceId(number, 1);
|
||||||
textsecure.storage.putUnencrypted('regionCode', libphonenumber.util.getRegionCodeForNumber(number));
|
textsecure.storage.putUnencrypted('regionCode', libphonenumber.util.getRegionCodeForNumber(number));
|
||||||
|
|
||||||
log('verifying code');
|
log('verifying code');
|
||||||
|
|
|
@ -74,9 +74,7 @@
|
||||||
var view = new Whisper.KeyVerificationView({
|
var view = new Whisper.KeyVerificationView({
|
||||||
model: {
|
model: {
|
||||||
their_key: textsecure.storage.devices.getIdentityKeyForNumber(number),
|
their_key: textsecure.storage.devices.getIdentityKeyForNumber(number),
|
||||||
your_key: textsecure.storage.devices.getIdentityKeyForNumber(
|
your_key: textsecure.storage.devices.getIdentityKeyForNumber(textsecure.storage.user.getNumber())
|
||||||
textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.$el.hide();
|
this.$el.hide();
|
||||||
|
|
|
@ -58,9 +58,7 @@
|
||||||
var view = new Whisper.KeyVerificationView({
|
var view = new Whisper.KeyVerificationView({
|
||||||
model: {
|
model: {
|
||||||
their_key: textsecure.storage.devices.getIdentityKeyForNumber(number),
|
their_key: textsecure.storage.devices.getIdentityKeyForNumber(number),
|
||||||
your_key: textsecure.storage.devices.getIdentityKeyForNumber(
|
your_key: textsecure.storage.devices.getIdentityKeyForNumber(textsecure.storage.user.getNumber())
|
||||||
textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.$el.hide();
|
this.$el.hide();
|
||||||
|
|
|
@ -95,7 +95,7 @@ window.textsecure.api = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param.do_auth) {
|
if (param.do_auth) {
|
||||||
param.user = textsecure.storage.getUnencrypted("number_id");
|
param.user = textsecure.storage.user.getNumber() + "." + textsecure.storage.user.getDeviceId();
|
||||||
param.password = textsecure.storage.getEncrypted("password");
|
param.password = textsecure.storage.getEncrypted("password");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ window.textsecure.api = function () {
|
||||||
var URL = URL_BASE.replace(/^http/g, 'ws') + url + '/?';
|
var URL = URL_BASE.replace(/^http/g, 'ws') + url + '/?';
|
||||||
var params = '';
|
var params = '';
|
||||||
if (auth) {
|
if (auth) {
|
||||||
var user = textsecure.storage.getUnencrypted("number_id");
|
var user = textsecure.storage.user.getNumber() + "." + textsecure.storage.user.getDeviceId();
|
||||||
var password = textsecure.storage.getEncrypted("password");
|
var password = textsecure.storage.getEncrypted("password");
|
||||||
var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
|
var params = 'login=%2B' + encodeURIComponent(user.substring(1)) + '&password=' + encodeURIComponent(password);
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ textsecure.processDecrypted = function(decrypted, source) {
|
||||||
if (decrypted.flags == null)
|
if (decrypted.flags == null)
|
||||||
decrypted.flags = 0;
|
decrypted.flags = 0;
|
||||||
|
|
||||||
if (decrypted.sync !== null && textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0] != source)
|
if (decrypted.sync !== null && textsecure.storage.user.getNumber() != source)
|
||||||
throw new Error("Got sync context on a message not from a peer device");
|
throw new Error("Got sync context on a message not from a peer device");
|
||||||
|
|
||||||
if ((decrypted.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
if ((decrypted.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||||
|
@ -266,8 +266,7 @@ window.textsecure.registerSingleDevice = function(number, verificationCode, step
|
||||||
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
||||||
|
|
||||||
return textsecure.api.confirmCode(number, verificationCode, password, signalingKey, registrationId, true).then(function() {
|
return textsecure.api.confirmCode(number, verificationCode, password, signalingKey, registrationId, true).then(function() {
|
||||||
var numberId = number + ".1";
|
textsecure.storage.user.setNumberAndDeviceId(number, 1);
|
||||||
textsecure.storage.putUnencrypted("number_id", numberId);
|
|
||||||
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
|
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
|
||||||
stepDone(1);
|
stepDone(1);
|
||||||
|
|
||||||
|
@ -297,8 +296,7 @@ window.textsecure.registerSecondDevice = function(encodedProvisionEnvelope, cryp
|
||||||
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
||||||
|
|
||||||
return textsecure.api.confirmCode(identityKey.number, identityKey.provisioningCode, password, signalingKey, registrationId, false).then(function(result) {
|
return textsecure.api.confirmCode(identityKey.number, identityKey.provisioningCode, password, signalingKey, registrationId, false).then(function(result) {
|
||||||
var numberId = identityKey.number + "." + result.deviceId;
|
textsecure.storage.user.setNumberAndDeviceId(identityKey.number, result.deviceId);
|
||||||
textsecure.storage.putUnencrypted("number_id", numberId);
|
|
||||||
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(identityKey.number));
|
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(identityKey.number));
|
||||||
stepDone(2);
|
stepDone(2);
|
||||||
|
|
||||||
|
|
|
@ -256,9 +256,8 @@ window.textsecure.messaging = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var sendSyncMessage = function(message, timestamp, destination) {
|
var sendSyncMessage = function(message, timestamp, destination) {
|
||||||
var numberDevice = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"));
|
var myNumber = textsecure.storage.user.getNumber();
|
||||||
var myNumber = numberDevice[0];
|
var myDevice = textsecure.storage.user.getDeviceId();
|
||||||
var myDevice = numberDevice[1];
|
|
||||||
if (myDevice != 1) {
|
if (myDevice != 1) {
|
||||||
var sync_message = textsecure.protobuf.PushMessageContent.decode(message.encode());
|
var sync_message = textsecure.protobuf.PushMessageContent.decode(message.encode());
|
||||||
sync_message.sync = new textsecure.protobuf.PushMessageContent.SyncMessageContext();
|
sync_message.sync = new textsecure.protobuf.PushMessageContent.SyncMessageContext();
|
||||||
|
@ -270,7 +269,7 @@ window.textsecure.messaging = function() {
|
||||||
|
|
||||||
var sendGroupProto = function(numbers, proto, timestamp) {
|
var sendGroupProto = function(numbers, proto, timestamp) {
|
||||||
timestamp = timestamp || Date.now();
|
timestamp = timestamp || Date.now();
|
||||||
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
|
var me = textsecure.storage.user.getNumber();
|
||||||
numbers = numbers.filter(function(number) { return number != me; });
|
numbers = numbers.filter(function(number) { return number != me; });
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
while (groupId === undefined || textsecure.storage.getEncrypted("group" + groupId) !== undefined)
|
while (groupId === undefined || textsecure.storage.getEncrypted("group" + groupId) !== undefined)
|
||||||
groupId = getString(textsecure.crypto.getRandomBytes(16));
|
groupId = getString(textsecure.crypto.getRandomBytes(16));
|
||||||
|
|
||||||
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
|
var me = textsecure.storage.user.getNumber();
|
||||||
var haveMe = false;
|
var haveMe = false;
|
||||||
var finalNumbers = [];
|
var finalNumbers = [];
|
||||||
for (var i in numbers) {
|
for (var i in numbers) {
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
if (group === undefined)
|
if (group === undefined)
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
||||||
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
|
var me = textsecure.storage.user.getNumber();
|
||||||
if (number == me)
|
if (number == me)
|
||||||
throw new Error("Cannot remove ourselves from a group, leave the group instead");
|
throw new Error("Cannot remove ourselves from a group, leave the group instead");
|
||||||
|
|
||||||
|
|
45
libtextsecure/storage/user.js
Normal file
45
libtextsecure/storage/user.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/* vim: ts=4:sw=4
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
;(function() {
|
||||||
|
/*********************************************
|
||||||
|
*** Utilities to store data about the user ***
|
||||||
|
**********************************************/
|
||||||
|
window.textsecure = window.textsecure || {};
|
||||||
|
window.textsecure.storage = window.textsecure.storage || {};
|
||||||
|
|
||||||
|
window.textsecure.storage.user = {
|
||||||
|
setNumberAndDeviceId: function(number, deviceId) {
|
||||||
|
textsecure.storage.putUnencrypted("number_id", number + "." + deviceId);
|
||||||
|
},
|
||||||
|
|
||||||
|
getNumber: function(key, defaultValue) {
|
||||||
|
var number_id = textsecure.storage.getUnencrypted("number_id");
|
||||||
|
if (number_id === undefined)
|
||||||
|
return undefined;
|
||||||
|
return textsecure.utils.unencodeNumber(number_id)[0];
|
||||||
|
},
|
||||||
|
|
||||||
|
getDeviceId: function(key) {
|
||||||
|
var number_id = textsecure.storage.getUnencrypted("number_id");
|
||||||
|
if (number_id === undefined)
|
||||||
|
return undefined;
|
||||||
|
return textsecure.utils.unencodeNumber(number_id)[1];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
Loading…
Add table
Add a link
Reference in a new issue