diff --git a/src/js/dao/devicestorage.js b/src/js/dao/devicestorage.js index 52dfe99..2cb1bdb 100644 --- a/src/js/dao/devicestorage.js +++ b/src/js/dao/devicestorage.js @@ -27,9 +27,9 @@ app.dao.DeviceStorage = function(util, crypto, jsonDao, sqlcipherDao) { // put date in key if available... for easy querying if (i.sentDate) { date = util.parseDate(i.sentDate); - key = crypto.emailAddress + '_' + type + '_' + date.getTime() + '_' + i.id; + key = type + '_' + i.sentDate + '_' + i.id; } else { - key = crypto.emailAddress + '_' + type + '_' + i.id; + key = type + '_' + i.id; } items.push({ @@ -52,7 +52,7 @@ app.dao.DeviceStorage = function(util, crypto, jsonDao, sqlcipherDao) { */ this.listEncryptedItems = function(type, offset, num, callback) { // fetch all items of a certain type from the data-store - jsonDao.list(crypto.emailAddress + '_' + type, offset, num, function(encryptedList) { + jsonDao.list(type, offset, num, function(encryptedList) { callback(null, encryptedList); }); diff --git a/src/js/dao/lawnchair-dao.js b/src/js/dao/lawnchair-dao.js index 7f5d9b5..5ec3ba8 100644 --- a/src/js/dao/lawnchair-dao.js +++ b/src/js/dao/lawnchair-dao.js @@ -5,7 +5,7 @@ app.dao.LawnchairDAO = function(Lawnchair) { 'use strict'; var db = new Lawnchair({ - name: 'data-store' + name: 'dataStore' }, function(lc) { if (!lc) { throw new Error('Lawnchair init failed!'); @@ -63,14 +63,6 @@ app.dao.LawnchairDAO = function(Lawnchair) { } } - // sort keys by type and date - matchingKeys = _.sortBy(matchingKeys, function(key) { - parts = key.split('_'); - timeStr = parts[parts.length - 2]; - time = parseInt(timeStr, 10); - return time; - }); - // if num is null, list all items num = (num !== null) ? num : matchingKeys.length; diff --git a/test/unit/devicestorage-test.js b/test/unit/devicestorage-test.js index eb6d47e..3cecb69 100644 --- a/test/unit/devicestorage-test.js +++ b/test/unit/devicestorage-test.js @@ -46,6 +46,10 @@ asyncTest("Encrypt list for user", 2, function() { ok(!err); equal(encryptedList.length, devicestorage_test.list.length, 'Encrypt list'); + encryptedList.forEach(function(i) { + i.sentDate = _.findWhere(devicestorage_test.list, {id: i.id}).sentDate; + }); + devicestorage_test.encryptedList = encryptedList; start(); }); @@ -67,7 +71,7 @@ asyncTest("List items", 4, function() { num = 6; // list encrypted items from storage - devicestorage_test.storage.listEncryptedItems('email_inbox_5', offset, num, function(err, encryptedList) { + devicestorage_test.storage.listEncryptedItems('email_inbox', offset, num, function(err, encryptedList) { ok(!err); // decrypt list @@ -75,15 +79,8 @@ asyncTest("List items", 4, function() { ok(!err); equal(decryptedList.length, num, 'Found ' + decryptedList.length + ' items in store (and decrypted)'); - var decrypted, orig = devicestorage_test.list[54]; - - // check ids - for (var i = 0; i < decryptedList.length; i++) { - if (decryptedList[i].id === orig.id && decryptedList[i].from === orig.from) { - deepEqual(decryptedList[i], orig, 'Messages decrypted correctly'); - break; - } - } + var origSet = devicestorage_test.list.splice(92, num); + deepEqual(decryptedList, origSet, 'Messages decrypted correctly'); start(); });