[local-sync] When fetching /new/ messages, make sure we have fetchedmax

Summary:
In `FetchNewMessagesInFolder`, sometimes we haven't synced anything in the folder
we are trying to fetch new messages in. Previously this would just throw
an error, now we properly check if we have a fetchedmax, and if not just
run a normal fetch.

Also, when the target folder box was already open, we were not fetching the /latest/ box status to check the latest uidnext value, so we would skip fetching new messages when in fact there were new messages to fetch

(This can happen for example when moving a sent message to the Sent
folder before we've started syncing the Sent folder)

Test Plan: manual

Reviewers: halla, mark, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3802
This commit is contained in:
Juan Tejada 2017-01-27 12:15:10 -08:00
parent a0356ca76f
commit e29fe2ee9b

View file

@ -17,15 +17,23 @@ class FetchNewMessagesInFolderIMAP extends FetchMessagesInFolderIMAP {
console.log(`🔜 📂 🆕 Looking for new messages in ${this._folder.name}`) console.log(`🔜 📂 🆕 Looking for new messages in ${this._folder.name}`)
this._db = db; this._db = db;
this._imap = imap; this._imap = imap;
const {syncState: {fetchedmax}} = this._folder
this._box = await this._imap.openBox(this._folder.name) if (!fetchedmax) {
// Without a fetchedmax, can't tell what's new!
// If we haven't fetched anything on this folder, let's run a normal fetch
// operation
yield super.runTask(db, imap)
return
}
if (this._shouldFetchMessages(this._box)) { const latestBoxStatus = yield this._imap.getLatestBoxStatus(this._folder.name)
if (latestBoxStatus.uidnext > fetchedmax) {
this._box = await this._imap.openBox(this._folder.name)
const boxUidnext = this._box.uidnext const boxUidnext = this._box.uidnext
const {syncState: {fetchedmax}} = this._folder
yield this._fetchAndProcessMessages({min: fetchedmax, max: boxUidnext}); yield this._fetchAndProcessMessages({min: fetchedmax, max: boxUidnext});
} else { } else {
console.log(`🔚 📂 ${this._folder.name} has no new messages - skipping fetch messages`) console.log(`🔚 📂 🆕$ {this._folder.name} has no new messages - skipping fetch messages`)
} }
console.log(`🔚 📂 ${this._folder.name} done`) console.log(`🔚 📂 ${this._folder.name} done`)
} }