From 8f1fd2de5f404abdf47a1831fb61d1ed713ef998 Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Wed, 5 Nov 2014 10:55:26 +0100 Subject: [PATCH 1/2] [WO-696] Order wellknown folders first, others alphabetically --- src/js/dao/email-dao.js | 27 ++++++++++++++++++++--- test/unit/email-dao-test.js | 44 ++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index 8c89ba6..a5362de 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -632,7 +632,7 @@ EmailDAO.prototype.setFlags = function(options, callback) { /** * Moves a message to another folder - * + * * @param {Object} options.folder The origin folder * @param {Object} options.destination The destination folder * @param {Object} options.message The message that should be moved @@ -1436,14 +1436,18 @@ EmailDAO.prototype._initFoldersFromImap = function(callback) { // // check for the well known folders to be displayed in the uppermost ui part - [ + // in that order + var wellknownTypes = [ FOLDER_TYPE_INBOX, FOLDER_TYPE_SENT, config.outboxMailboxType, FOLDER_TYPE_DRAFTS, FOLDER_TYPE_FLAGGED, FOLDER_TYPE_TRASH - ].forEach(function(mbxType) { + ]; + + // make sure the well known folders are detected + wellknownTypes.forEach(function(mbxType) { // check if there is a well known folder of this type var wellknownFolder = _.findWhere(self._account.folders, { type: mbxType, @@ -1471,6 +1475,23 @@ EmailDAO.prototype._initFoldersFromImap = function(callback) { foldersChanged = true; }); + // order folders + self._account.folders.sort(function(a, b) { + if (a.wellknown && b.wellknown) { + // well known folders should be ordered like the types in the wellknownTypes array + return wellknownTypes.indexOf(a.type) - wellknownTypes.indexOf(b.type); + } else if (a.wellknown && !b.wellknown) { + // wellknown folders should always appear BEFORE the other folders + return -1; + } else if (!a.wellknown && b.wellknown) { + // non-wellknown folders should always appear AFTER wellknown folders + return 1; + } else { + // non-wellknown folders should be sorted case-insensitive + return a.name.toLowerCase().localeCompare(b.name.toLowerCase()); + } + }); + // if folders have not changed, can fill them with messages directly if (!foldersChanged) { return self._initMessagesFromDisk(done); diff --git a/test/unit/email-dao-test.js b/test/unit/email-dao-test.js index 646aac6..8f467c0 100644 --- a/test/unit/email-dao-test.js +++ b/test/unit/email-dao-test.js @@ -2114,18 +2114,18 @@ describe('Email DAO unit tests', function() { expect(arg[0][1].name).to.deep.equal(sentFolder.name); expect(arg[0][1].path).to.deep.equal(sentFolder.path); expect(arg[0][1].type).to.deep.equal(sentFolder.type); - expect(arg[0][2].name).to.deep.equal(draftsFolder.name); - expect(arg[0][2].path).to.deep.equal(draftsFolder.path); - expect(arg[0][2].type).to.deep.equal(draftsFolder.type); - expect(arg[0][3].name).to.deep.equal(trashFolder.name); - expect(arg[0][3].path).to.deep.equal(trashFolder.path); - expect(arg[0][3].type).to.deep.equal(trashFolder.type); - expect(arg[0][4].name).to.deep.equal(otherFolder.name); - expect(arg[0][4].path).to.deep.equal(otherFolder.path); - expect(arg[0][4].type).to.deep.equal(otherFolder.type); - expect(arg[0][5].name).to.deep.equal(outboxFolder.name); - expect(arg[0][5].path).to.deep.equal(outboxFolder.path); - expect(arg[0][5].type).to.deep.equal(outboxFolder.type); + expect(arg[0][2].name).to.deep.equal(outboxFolder.name); + expect(arg[0][2].path).to.deep.equal(outboxFolder.path); + expect(arg[0][2].type).to.deep.equal(outboxFolder.type); + expect(arg[0][3].name).to.deep.equal(draftsFolder.name); + expect(arg[0][3].path).to.deep.equal(draftsFolder.path); + expect(arg[0][3].type).to.deep.equal(draftsFolder.type); + expect(arg[0][4].name).to.deep.equal(trashFolder.name); + expect(arg[0][4].path).to.deep.equal(trashFolder.path); + expect(arg[0][4].type).to.deep.equal(trashFolder.type); + expect(arg[0][5].name).to.deep.equal(otherFolder.name); + expect(arg[0][5].path).to.deep.equal(otherFolder.path); + expect(arg[0][5].type).to.deep.equal(otherFolder.type); return true; }), 'folders').yieldsAsync(); @@ -2159,26 +2159,26 @@ describe('Email DAO unit tests', function() { path: inboxFolder.path, type: inboxFolder.type, wellknown: true - }, { - name: outboxFolder.name, - path: outboxFolder.path, - type: outboxFolder.type, - wellknown: true - }, { - name: trashFolder.name, - path: trashFolder.path, - type: trashFolder.type, - wellknown: true }, { name: sentFolder.name, path: sentFolder.path, type: sentFolder.type, wellknown: true + }, { + name: outboxFolder.name, + path: outboxFolder.path, + type: outboxFolder.type, + wellknown: true }, { name: draftsFolder.name, path: draftsFolder.path, type: draftsFolder.type, wellknown: true + }, { + name: trashFolder.name, + path: trashFolder.path, + type: trashFolder.type, + wellknown: true }, { name: otherFolder.name, path: otherFolder.path, From 14dc80ec3c3e305d61d6b86562b70046b6c8d7cc Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Wed, 5 Nov 2014 11:36:42 +0100 Subject: [PATCH 2/2] [WO-696] List trash before flagged in wellknown folders --- src/js/dao/email-dao.js | 4 ++-- test/unit/email-dao-test.js | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index a5362de..28097e9 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -1442,8 +1442,8 @@ EmailDAO.prototype._initFoldersFromImap = function(callback) { FOLDER_TYPE_SENT, config.outboxMailboxType, FOLDER_TYPE_DRAFTS, - FOLDER_TYPE_FLAGGED, - FOLDER_TYPE_TRASH + FOLDER_TYPE_TRASH, + FOLDER_TYPE_FLAGGED ]; // make sure the well known folders are detected diff --git a/test/unit/email-dao-test.js b/test/unit/email-dao-test.js index 8f467c0..e602163 100644 --- a/test/unit/email-dao-test.js +++ b/test/unit/email-dao-test.js @@ -25,7 +25,7 @@ describe('Email DAO unit tests', function() { var emailAddress, passphrase, asymKeySize, account; // test data - var folders, inboxFolder, sentFolder, draftsFolder, outboxFolder, trashFolder, otherFolder, mockKeyPair; + var folders, inboxFolder, sentFolder, draftsFolder, outboxFolder, trashFolder, flaggedFolder, otherFolder, mockKeyPair; beforeEach(function() { // @@ -70,6 +70,13 @@ describe('Email DAO unit tests', function() { messages: [] }; + flaggedFolder = { + name: 'Flagged', + type: 'Flagged', + path: 'FLAGGED', + messages: [] + }; + otherFolder = { name: 'Other', type: 'Other', @@ -2105,6 +2112,7 @@ describe('Email DAO unit tests', function() { Sent: [sentFolder], Drafts: [draftsFolder], Trash: [trashFolder], + Flagged: [flaggedFolder], Other: [otherFolder] }); devicestorageStub.storeList.withArgs(sinon.match(function(arg) { @@ -2123,9 +2131,12 @@ describe('Email DAO unit tests', function() { expect(arg[0][4].name).to.deep.equal(trashFolder.name); expect(arg[0][4].path).to.deep.equal(trashFolder.path); expect(arg[0][4].type).to.deep.equal(trashFolder.type); - expect(arg[0][5].name).to.deep.equal(otherFolder.name); - expect(arg[0][5].path).to.deep.equal(otherFolder.path); - expect(arg[0][5].type).to.deep.equal(otherFolder.type); + expect(arg[0][5].name).to.deep.equal(flaggedFolder.name); + expect(arg[0][5].path).to.deep.equal(flaggedFolder.path); + expect(arg[0][5].type).to.deep.equal(flaggedFolder.type); + expect(arg[0][6].name).to.deep.equal(otherFolder.name); + expect(arg[0][6].path).to.deep.equal(otherFolder.path); + expect(arg[0][6].type).to.deep.equal(otherFolder.type); return true; }), 'folders').yieldsAsync(); @@ -2151,6 +2162,7 @@ describe('Email DAO unit tests', function() { Sent: [sentFolder], Drafts: [draftsFolder], Trash: [trashFolder], + Flagged: [flaggedFolder], Other: [otherFolder] }); devicestorageStub.storeList.withArgs(sinon.match(function(arg) { @@ -2179,6 +2191,11 @@ describe('Email DAO unit tests', function() { path: trashFolder.path, type: trashFolder.type, wellknown: true + }, { + name: flaggedFolder.name, + path: flaggedFolder.path, + type: flaggedFolder.type, + wellknown: true }, { name: otherFolder.name, path: otherFolder.path,