sync completion when signed out

This commit is contained in:
Mo Bitar
2017-01-14 11:02:28 -06:00
parent 8b7f7d84d9
commit 97ff87d43a
4 changed files with 34 additions and 22 deletions

View File

@@ -108,7 +108,7 @@ angular.module('app.frontend')
_.merge(request, params); _.merge(request, params);
request.post().then(function(response){ request.post().then(function(response){
localStorage.setItem("jwt", response.token); localStorage.setItem("jwt", response.token);
localStorage.setItem("uuid", response.uuid); localStorage.setItem("uuid", response.user.uuid);
localStorage.setItem("auth_params", JSON.stringify(authParams)); localStorage.setItem("auth_params", JSON.stringify(authParams));
callback(response); callback(response);
}) })
@@ -128,7 +128,7 @@ angular.module('app.frontend')
_.merge(request, params); _.merge(request, params);
request.post().then(function(response){ request.post().then(function(response){
localStorage.setItem("jwt", response.token); localStorage.setItem("jwt", response.token);
localStorage.setItem("uuid", response.uuid); localStorage.setItem("uuid", response.user.uuid);
localStorage.setItem("auth_params", JSON.stringify(_.omit(authParams, ["pw_nonce"]))); localStorage.setItem("auth_params", JSON.stringify(_.omit(authParams, ["pw_nonce"])));
callback(response); callback(response);
}) })
@@ -247,6 +247,7 @@ angular.module('app.frontend')
} }
}.bind(this)) }.bind(this))
this.syncOpInProgress = false;
return; return;
} }
@@ -519,7 +520,7 @@ angular.module('app.frontend')
this.writeItemsToLocalStorage = function(items, callback) { this.writeItemsToLocalStorage = function(items, callback) {
var params = items.map(function(item) { var params = items.map(function(item) {
return this.paramsForItem(item, this.isUserSignedIn(), ["created_at", "updated_at", "presentation_url", "dirty"], false) return this.paramsForItem(item, false, ["created_at", "updated_at", "presentation_url", "dirty"], true)
}.bind(this)); }.bind(this));
dbManager.saveItems(params, callback); dbManager.saveItems(params, callback);
@@ -624,12 +625,17 @@ angular.module('app.frontend')
} }
var isString = typeof item.content === 'string' || item.content instanceof String; var isString = typeof item.content === 'string' || item.content instanceof String;
if(isString) { if(isString) {
if(item.content.substring(0, 3) == "001" && item.enc_item_key) { try {
// is encrypted if(item.content.substring(0, 3) == "001" && item.enc_item_key) {
this.decryptSingleItem(item, key); // is encrypted
} else { this.decryptSingleItem(item, key);
// is base64 encoded } else {
item.content = Neeto.crypto.base64Decode(item.content.substring(3, item.content.length)) // is base64 encoded
item.content = Neeto.crypto.base64Decode(item.content.substring(3, item.content.length))
}
} catch (e) {
console.log("Error decrypting item", item);
continue;
} }
} }
} }

View File

@@ -58,7 +58,7 @@ class DBManager {
} }
saveItem(item) { saveItem(item) {
saveItems([item]); this.saveItems([item]);
} }
saveItems(items, callback) { saveItems(items, callback) {

View File

@@ -958,7 +958,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
// refresh every 30s // refresh every 30s
setInterval(function () { setInterval(function () {
apiController.sync(null); apiController.sync(null);
}, 2000); }, 30000);
}); });
$scope.allTag = new Tag({ all: true }); $scope.allTag = new Tag({ all: true });
@@ -2015,7 +2015,7 @@ var Tag = function (_Item3) {
_.merge(request, params); _.merge(request, params);
request.post().then(function (response) { request.post().then(function (response) {
localStorage.setItem("jwt", response.token); localStorage.setItem("jwt", response.token);
localStorage.setItem("uuid", response.uuid); localStorage.setItem("uuid", response.user.uuid);
localStorage.setItem("auth_params", JSON.stringify(authParams)); localStorage.setItem("auth_params", JSON.stringify(authParams));
callback(response); callback(response);
}).catch(function (response) { }).catch(function (response) {
@@ -2034,7 +2034,7 @@ var Tag = function (_Item3) {
_.merge(request, params); _.merge(request, params);
request.post().then(function (response) { request.post().then(function (response) {
localStorage.setItem("jwt", response.token); localStorage.setItem("jwt", response.token);
localStorage.setItem("uuid", response.uuid); localStorage.setItem("uuid", response.user.uuid);
localStorage.setItem("auth_params", JSON.stringify(_.omit(authParams, ["pw_nonce"]))); localStorage.setItem("auth_params", JSON.stringify(_.omit(authParams, ["pw_nonce"])));
callback(response); callback(response);
}).catch(function (response) { }).catch(function (response) {
@@ -2152,6 +2152,7 @@ var Tag = function (_Item3) {
} }
}.bind(this)); }.bind(this));
this.syncOpInProgress = false;
return; return;
} }
@@ -2438,7 +2439,7 @@ var Tag = function (_Item3) {
this.writeItemsToLocalStorage = function (items, callback) { this.writeItemsToLocalStorage = function (items, callback) {
var params = items.map(function (item) { var params = items.map(function (item) {
return this.paramsForItem(item, this.isUserSignedIn(), ["created_at", "updated_at", "presentation_url", "dirty"], false); return this.paramsForItem(item, false, ["created_at", "updated_at", "presentation_url", "dirty"], true);
}.bind(this)); }.bind(this));
dbManager.saveItems(params, callback); dbManager.saveItems(params, callback);
@@ -2548,12 +2549,17 @@ var Tag = function (_Item3) {
} }
var isString = typeof item.content === 'string' || item.content instanceof String; var isString = typeof item.content === 'string' || item.content instanceof String;
if (isString) { if (isString) {
if (item.content.substring(0, 3) == "001" && item.enc_item_key) { try {
// is encrypted if (item.content.substring(0, 3) == "001" && item.enc_item_key) {
this.decryptSingleItem(item, key); // is encrypted
} else { this.decryptSingleItem(item, key);
// is base64 encoded } else {
item.content = Neeto.crypto.base64Decode(item.content.substring(3, item.content.length)); // is base64 encoded
item.content = Neeto.crypto.base64Decode(item.content.substring(3, item.content.length));
}
} catch (e) {
console.log("Error decrypting item", item);
continue;
} }
} }
} }
@@ -2657,7 +2663,7 @@ var DBManager = function () {
}, { }, {
key: 'saveItem', key: 'saveItem',
value: function saveItem(item) { value: function saveItem(item) {
saveItems([item]); this.saveItems([item]);
} }
}, { }, {
key: 'saveItems', key: 'saveItems',

File diff suppressed because one or more lines are too long