diff --git a/internal_packages/worker-sync/lib/nylas-sync-worker.coffee b/internal_packages/worker-sync/lib/nylas-sync-worker.coffee index a6c7a8f4f..fbe34d8c4 100644 --- a/internal_packages/worker-sync/lib/nylas-sync-worker.coffee +++ b/internal_packages/worker-sync/lib/nylas-sync-worker.coffee @@ -1,5 +1,5 @@ _ = require 'underscore' -{Actions, DatabaseStore} = require 'nylas-exports' +{Actions, DatabaseStore, NylasSyncStatusStore} = require 'nylas-exports' NylasLongConnection = require './nylas-long-connection' ContactRankingsCache = require './contact-rankings-cache' @@ -71,7 +71,7 @@ class NylasSyncWorker DatabaseStore.findJSONBlob("NylasSyncWorker:#{@_account.id}").then (json) => @_state = json ? {} @_state.longConnectionStatus = NylasLongConnection.Status.Idle - for key in ['threads', 'labels', 'folders', 'drafts', 'contacts', 'calendars', 'events'] + for key in NylasSyncStatusStore.ModelsForSync @_state[key].busy = false if @_state[key] @resume() diff --git a/src/flux/stores/nylas-sync-status-store.coffee b/src/flux/stores/nylas-sync-status-store.coffee index 7cf3a3a37..c77f13b78 100644 --- a/src/flux/stores/nylas-sync-status-store.coffee +++ b/src/flux/stores/nylas-sync-status-store.coffee @@ -4,7 +4,19 @@ AccountStore = require './account-store' DatabaseStore = require './database-store' NylasStore = require 'nylas-store' +ModelsForSync = [ + 'threads', + 'messages', + 'labels', + 'folders', + 'drafts', + 'contacts', + 'calendars', + 'events' +] + class NylasSyncStatusStore extends NylasStore + ModelsForSync: ModelsForSync constructor: -> @_statesByAccount = {} @@ -29,12 +41,13 @@ class NylasSyncStatusStore extends NylasStore return false unless @_statesByAccount[acctId] if model return @_statesByAccount[acctId][model]?.complete ? false - for _model, modelState of @_statesByAccount[acctId] - continue if _model in ['longConnectionStatus', 'nextRetryTimestamp'] - return false if not modelState.complete + for _model in ModelsForSync + modelState = @_statesByAccount[_model] + return false if not modelState?.complete return true isSyncComplete: => + return false if _.isEmpty(@_statesByAccount) for acctId of @_statesByAccount return false if not @isSyncCompleteForAccount(acctId) return true