mirror of
https://github.com/moparisthebest/mail
synced 2024-11-26 02:42:17 -05:00
[WO-696] Order wellknown folders first, others alphabetically
This commit is contained in:
parent
7d223dc851
commit
8f1fd2de5f
@ -632,7 +632,7 @@ EmailDAO.prototype.setFlags = function(options, callback) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves a message to another folder
|
* Moves a message to another folder
|
||||||
*
|
*
|
||||||
* @param {Object} options.folder The origin folder
|
* @param {Object} options.folder The origin folder
|
||||||
* @param {Object} options.destination The destination folder
|
* @param {Object} options.destination The destination folder
|
||||||
* @param {Object} options.message The message that should be moved
|
* @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
|
// check for the well known folders to be displayed in the uppermost ui part
|
||||||
[
|
// in that order
|
||||||
|
var wellknownTypes = [
|
||||||
FOLDER_TYPE_INBOX,
|
FOLDER_TYPE_INBOX,
|
||||||
FOLDER_TYPE_SENT,
|
FOLDER_TYPE_SENT,
|
||||||
config.outboxMailboxType,
|
config.outboxMailboxType,
|
||||||
FOLDER_TYPE_DRAFTS,
|
FOLDER_TYPE_DRAFTS,
|
||||||
FOLDER_TYPE_FLAGGED,
|
FOLDER_TYPE_FLAGGED,
|
||||||
FOLDER_TYPE_TRASH
|
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
|
// check if there is a well known folder of this type
|
||||||
var wellknownFolder = _.findWhere(self._account.folders, {
|
var wellknownFolder = _.findWhere(self._account.folders, {
|
||||||
type: mbxType,
|
type: mbxType,
|
||||||
@ -1471,6 +1475,23 @@ EmailDAO.prototype._initFoldersFromImap = function(callback) {
|
|||||||
foldersChanged = true;
|
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 folders have not changed, can fill them with messages directly
|
||||||
if (!foldersChanged) {
|
if (!foldersChanged) {
|
||||||
return self._initMessagesFromDisk(done);
|
return self._initMessagesFromDisk(done);
|
||||||
|
@ -2114,18 +2114,18 @@ describe('Email DAO unit tests', function() {
|
|||||||
expect(arg[0][1].name).to.deep.equal(sentFolder.name);
|
expect(arg[0][1].name).to.deep.equal(sentFolder.name);
|
||||||
expect(arg[0][1].path).to.deep.equal(sentFolder.path);
|
expect(arg[0][1].path).to.deep.equal(sentFolder.path);
|
||||||
expect(arg[0][1].type).to.deep.equal(sentFolder.type);
|
expect(arg[0][1].type).to.deep.equal(sentFolder.type);
|
||||||
expect(arg[0][2].name).to.deep.equal(draftsFolder.name);
|
expect(arg[0][2].name).to.deep.equal(outboxFolder.name);
|
||||||
expect(arg[0][2].path).to.deep.equal(draftsFolder.path);
|
expect(arg[0][2].path).to.deep.equal(outboxFolder.path);
|
||||||
expect(arg[0][2].type).to.deep.equal(draftsFolder.type);
|
expect(arg[0][2].type).to.deep.equal(outboxFolder.type);
|
||||||
expect(arg[0][3].name).to.deep.equal(trashFolder.name);
|
expect(arg[0][3].name).to.deep.equal(draftsFolder.name);
|
||||||
expect(arg[0][3].path).to.deep.equal(trashFolder.path);
|
expect(arg[0][3].path).to.deep.equal(draftsFolder.path);
|
||||||
expect(arg[0][3].type).to.deep.equal(trashFolder.type);
|
expect(arg[0][3].type).to.deep.equal(draftsFolder.type);
|
||||||
expect(arg[0][4].name).to.deep.equal(otherFolder.name);
|
expect(arg[0][4].name).to.deep.equal(trashFolder.name);
|
||||||
expect(arg[0][4].path).to.deep.equal(otherFolder.path);
|
expect(arg[0][4].path).to.deep.equal(trashFolder.path);
|
||||||
expect(arg[0][4].type).to.deep.equal(otherFolder.type);
|
expect(arg[0][4].type).to.deep.equal(trashFolder.type);
|
||||||
expect(arg[0][5].name).to.deep.equal(outboxFolder.name);
|
expect(arg[0][5].name).to.deep.equal(otherFolder.name);
|
||||||
expect(arg[0][5].path).to.deep.equal(outboxFolder.path);
|
expect(arg[0][5].path).to.deep.equal(otherFolder.path);
|
||||||
expect(arg[0][5].type).to.deep.equal(outboxFolder.type);
|
expect(arg[0][5].type).to.deep.equal(otherFolder.type);
|
||||||
return true;
|
return true;
|
||||||
}), 'folders').yieldsAsync();
|
}), 'folders').yieldsAsync();
|
||||||
|
|
||||||
@ -2159,26 +2159,26 @@ describe('Email DAO unit tests', function() {
|
|||||||
path: inboxFolder.path,
|
path: inboxFolder.path,
|
||||||
type: inboxFolder.type,
|
type: inboxFolder.type,
|
||||||
wellknown: true
|
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,
|
name: sentFolder.name,
|
||||||
path: sentFolder.path,
|
path: sentFolder.path,
|
||||||
type: sentFolder.type,
|
type: sentFolder.type,
|
||||||
wellknown: true
|
wellknown: true
|
||||||
|
}, {
|
||||||
|
name: outboxFolder.name,
|
||||||
|
path: outboxFolder.path,
|
||||||
|
type: outboxFolder.type,
|
||||||
|
wellknown: true
|
||||||
}, {
|
}, {
|
||||||
name: draftsFolder.name,
|
name: draftsFolder.name,
|
||||||
path: draftsFolder.path,
|
path: draftsFolder.path,
|
||||||
type: draftsFolder.type,
|
type: draftsFolder.type,
|
||||||
wellknown: true
|
wellknown: true
|
||||||
|
}, {
|
||||||
|
name: trashFolder.name,
|
||||||
|
path: trashFolder.path,
|
||||||
|
type: trashFolder.type,
|
||||||
|
wellknown: true
|
||||||
}, {
|
}, {
|
||||||
name: otherFolder.name,
|
name: otherFolder.name,
|
||||||
path: otherFolder.path,
|
path: otherFolder.path,
|
||||||
|
Loading…
Reference in New Issue
Block a user