Merge pull request #185 from whiteout-io/dev/wo-731

[WO-731] Treat modseq values as numbers
This commit is contained in:
Felix Hammerl 2014-11-14 12:14:43 +01:00
commit 21356ae9ac
2 changed files with 14 additions and 9 deletions

View File

@ -1154,7 +1154,7 @@ EmailDAO.prototype.onConnect = function(options, callback) {
self._imapClient.onSyncUpdate = self._onSyncUpdate.bind(self); self._imapClient.onSyncUpdate = self._onSyncUpdate.bind(self);
// fill the imap mailboxCache with information we have locally available: // fill the imap mailboxCache with information we have locally available:
// - highest locally available moseq // - highest locally available moseq (NB! JavaScript can't handle 64 bit uints, so modseq values are strings)
// - list of locally available uids // - list of locally available uids
// - highest locally available uid // - highest locally available uid
// - next expected uid // - next expected uid
@ -1172,8 +1172,13 @@ EmailDAO.prototype.onConnect = function(options, callback) {
lastUid = uids[uids.length - 1]; lastUid = uids[uids.length - 1];
highestModseq = _.pluck(folder.messages, 'modseq').sort(function(a, b) { highestModseq = _.pluck(folder.messages, 'modseq').sort(function(a, b) {
return a - b; // We treat modseq values as numbers here as an exception, should
}).pop(); // be strings everywhere else.
// If it turns out that someone actually uses 64 bit uint numbers
// that do not fit to the JavaScript number type then we should
// use a helper for handling big integers.
return (Number(a) || 0) - (Number(b) || 0);
}).pop().toString();
mailboxCache[folder.path] = { mailboxCache[folder.path] = {
exists: lastUid, exists: lastUid,
@ -1396,9 +1401,9 @@ EmailDAO.prototype._initFoldersFromImap = function(callback) {
})); }));
}); });
// //
// by now, all the folders are up to date. now we need to find all the well known folders // by now, all the folders are up to date. now we need to find all the well known folders
// //
// 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 // in that order
@ -1424,7 +1429,7 @@ EmailDAO.prototype._initFoldersFromImap = function(callback) {
return; return;
} }
// we have no folder of the respective type marked as wellknown, so find the // we have no folder of the respective type marked as wellknown, so find the
// next best folder of the respective type and flag it as wellknown so that // next best folder of the respective type and flag it as wellknown so that
// we can display it properly // we can display it properly
wellknownFolder = _.findWhere(self._account.folders, { wellknownFolder = _.findWhere(self._account.folders, {

View File

@ -910,7 +910,7 @@ describe('Email DAO unit tests', function() {
var localListStub, localStoreStub, imapGetStub, uid; var localListStub, localStoreStub, imapGetStub, uid;
beforeEach(function() { beforeEach(function() {
uid = 12345, uid = 12345;
localListStub = sinon.stub(dao, '_localListMessages'); localListStub = sinon.stub(dao, '_localListMessages');
localStoreStub = sinon.stub(dao, '_localStoreMessages'); localStoreStub = sinon.stub(dao, '_localStoreMessages');
imapGetStub = sinon.stub(dao, '_getBodyParts'); imapGetStub = sinon.stub(dao, '_getBodyParts');
@ -1842,7 +1842,7 @@ describe('Email DAO unit tests', function() {
it('should connect', function(done) { it('should connect', function(done) {
inboxFolder.messages = [{ inboxFolder.messages = [{
uid: 123, uid: 123,
modseq: 123 modseq: '123'
}]; }];
imapClientStub.login.yieldsAsync(); imapClientStub.login.yieldsAsync();
imapClientStub.listenForChanges.yieldsAsync(); imapClientStub.listenForChanges.yieldsAsync();
@ -1862,7 +1862,7 @@ describe('Email DAO unit tests', function() {
exists: 123, exists: 123,
uidNext: 124, uidNext: 124,
uidlist: [123], uidlist: [123],
highestModseq: 123 highestModseq: '123'
} }
}); });