Fix some bugs recently introduced

This commit is contained in:
Matt Corallo 2014-05-26 00:45:22 +02:00
parent 21b95ce1d3
commit ac48d552fa
2 changed files with 22 additions and 17 deletions

View file

@ -61,7 +61,7 @@ window.textsecure.api = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
$.ajax(URL_BASE + URL_CALLS[param.call] + param.urlParameters, { $.ajax(URL_BASE + URL_CALLS[param.call] + param.urlParameters, {
type : param.httpType, type : param.httpType,
data : param.jsonData && jsonThing(param.jsonData), data : param.jsonData && textsecure.utils.jsonThing(param.jsonData),
contentType : 'application/json; charset=utf-8', contentType : 'application/json; charset=utf-8',
dataType : 'json', dataType : 'json',

View file

@ -194,6 +194,10 @@ window.textsecure.protos = function() {
window.textsecure.utils = function() { window.textsecure.utils = function() {
var self = {}; var self = {};
/****************************************
*** Number conversion/checking stuff ***
****************************************/
function isNumeric(string) { function isNumeric(string) {
return string.replace(/\D/g, '') === string; return string.replace(/\D/g, '') === string;
} }
@ -244,22 +248,14 @@ window.textsecure.utils = function() {
return '+' + country_code + number; return '+' + country_code + number;
} }
self.unencodeNumber(number) { self.unencodeNumber = function(number) {
return string.split(".")[0]; return number.split(".")[0];
} }
return self;
}
/************************************************ /**************************
*** Utilities to store data in local storage *** *** JSON'ing Utilities ***
************************************************/ **************************/
window.textsecure.storage = function() {
var self = {};
/****************************
*** Conversion Utilities ***
****************************/
function ensureStringed(thing) { function ensureStringed(thing) {
if (getStringable(thing)) if (getStringable(thing))
return getString(thing); return getString(thing);
@ -278,10 +274,19 @@ window.textsecure.storage = function() {
} }
function jsonThing(thing) { self.jsonThing = function(thing) {
return JSON.stringify(ensureStringed(thing)); return JSON.stringify(ensureStringed(thing));
} }
return self;
}();
/************************************************
*** Utilities to store data in local storage ***
************************************************/
window.textsecure.storage = function() {
var self = {};
/***************************** /*****************************
*** Base Storage Routines *** *** Base Storage Routines ***
*****************************/ *****************************/
@ -289,7 +294,7 @@ window.textsecure.storage = function() {
//TODO //TODO
if (value === undefined) if (value === undefined)
throw new Error("Tried to store undefined"); throw new Error("Tried to store undefined");
localStorage.setItem("e" + key, jsonThing(value)); localStorage.setItem("e" + key, textsecure.utils.jsonThing(value));
} }
self.getEncrypted = function(key, defaultValue) { self.getEncrypted = function(key, defaultValue) {
@ -307,7 +312,7 @@ window.textsecure.storage = function() {
self.putUnencrypted = function(key, value) { self.putUnencrypted = function(key, value) {
if (value === undefined) if (value === undefined)
throw new Error("Tried to store undefined"); throw new Error("Tried to store undefined");
localStorage.setItem("u" + key, jsonThing(value)); localStorage.setItem("u" + key, textsecure.utils.jsonThing(value));
} }
self.getUnencrypted = function(key, defaultValue) { self.getUnencrypted = function(key, defaultValue) {