[client-sync] Ensure allmail folder exists before trying to access it

Summary:
When checking for flag updates for gmail accounts, when syncing for the
first time the all mail folder won't be available because we haven't
fetched the folder list, so it will throw a runtime error

Test Plan: manual

Reviewers: mark, halla

Reviewed By: halla

Differential Revision: https://phab.nylas.com/D4405
This commit is contained in:
Juan Tejada 2017-04-11 12:30:07 -07:00
parent d226eaf4a7
commit 0525767518

View file

@ -293,9 +293,11 @@ class SyncWorker {
if (this._account.provider === "gmail") {
const checkForAttributeUpdates = async () => {
const allMailFolder = await this._db.Folder.findOne({where: {role: 'all'}})
const allMailBox = await this._mailListenerIMAPConn.getLatestBoxStatus(allMailFolder.name)
if (allMailFolder.syncState.highestmodseq !== allMailBox.highestmodseq) {
onUpdate();
if (allMailFolder) {
const allMailBox = await this._mailListenerIMAPConn.getLatestBoxStatus(allMailFolder.name)
if (allMailFolder.syncState.highestmodseq !== allMailBox.highestmodseq) {
onUpdate();
}
}
this._mailListenerAttrPollTimeout = setTimeout(checkForAttributeUpdates, 30 * 1000)
}