From 072a9606e15f0160e07fc159c7f418a75be1ee98 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 15 Sep 2016 21:22:47 -0400 Subject: [PATCH] cached sites for current tab page --- src/models/domainModels.js | 1 + src/popup/app/current/currentController.js | 62 ++++------------------ 2 files changed, 12 insertions(+), 51 deletions(-) diff --git a/src/models/domainModels.js b/src/models/domainModels.js index f98ee9910e..8395e016ff 100644 --- a/src/models/domainModels.js +++ b/src/models/domainModels.js @@ -87,6 +87,7 @@ var Folder = function (obj, alreadyEncrypted) { return null; }).then(function (val) { model.uri = val; + model.domain = tldjs.getDomain(val); if (self.username) { return self.username.decryptWithPromise(); } diff --git a/src/popup/app/current/currentController.js b/src/popup/app/current/currentController.js index c23f545e07..7574511ec1 100644 --- a/src/popup/app/current/currentController.js +++ b/src/popup/app/current/currentController.js @@ -29,61 +29,21 @@ angular $scope.canAutofill = true; }); - var filteredPromises = [], - filteredSites = [], - promises = [], - decSites = []; + var filteredSites = [], + promises = []; - siteService.getAll(function (sites) { + var sitePromise = $q.when(siteService.getAllDecrypted()); + sitePromise.then(function (sites) { for (var i = 0; i < sites.length; i++) { - var uriPromise = cipherService.decrypt(sites[i].uri, i); - filteredPromises.push(uriPromise); - uriPromise.then(function (obj) { - if (!obj.val) { - return; - } - - var siteDomain = tldjs.getDomain(obj.val); - if (!siteDomain || siteDomain != domain) { - return; - } - - filteredSites.push(obj.index); - }); - } - - $q.all(filteredPromises).then(function () { - for (var j = 0; j < filteredSites.length; j++) { - var index = filteredSites[j]; - decSites.push({ - id: sites[index].id, - folderId: sites[index].folderId, - favorite: sites[index].favorite - }); - - var namePromise = cipherService.decrypt(sites[index].name, j); - promises.push(namePromise); - namePromise.then(function (obj) { - decSites[obj.index].name = obj.val; - }); - - var usernamePromise = cipherService.decrypt(sites[index].username, j); - promises.push(usernamePromise); - usernamePromise.then(function (obj) { - decSites[obj.index].username = obj.val; - }); - - var passwordPromise = cipherService.decrypt(sites[index].password, j); - promises.push(passwordPromise); - passwordPromise.then(function (obj) { - decSites[obj.index].password = obj.val; - }); + if (sites[i].domain && sites[i].domain == domain) { + filteredSites.push(sites[i]); } + } + }); + promises.push(sitePromise); - $q.all(promises).then(function () { - $scope.sites = decSites; - }); - }); + $q.all(promises).then(function () { + $scope.sites = filteredSites; }); });