fix(sync-status): Fix logic for checking sync status:

- Only check sync status keys that belong to actual models being synced
- Return false if state object is empty
This commit is contained in:
Juan Tejada 2016-04-05 13:27:48 -07:00
parent 79e15e8408
commit eb1f9409ef
2 changed files with 18 additions and 5 deletions

View file

@ -1,5 +1,5 @@
_ = require 'underscore' _ = require 'underscore'
{Actions, DatabaseStore} = require 'nylas-exports' {Actions, DatabaseStore, NylasSyncStatusStore} = require 'nylas-exports'
NylasLongConnection = require './nylas-long-connection' NylasLongConnection = require './nylas-long-connection'
ContactRankingsCache = require './contact-rankings-cache' ContactRankingsCache = require './contact-rankings-cache'
@ -71,7 +71,7 @@ class NylasSyncWorker
DatabaseStore.findJSONBlob("NylasSyncWorker:#{@_account.id}").then (json) => DatabaseStore.findJSONBlob("NylasSyncWorker:#{@_account.id}").then (json) =>
@_state = json ? {} @_state = json ? {}
@_state.longConnectionStatus = NylasLongConnection.Status.Idle @_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] @_state[key].busy = false if @_state[key]
@resume() @resume()

View file

@ -4,7 +4,19 @@ AccountStore = require './account-store'
DatabaseStore = require './database-store' DatabaseStore = require './database-store'
NylasStore = require 'nylas-store' NylasStore = require 'nylas-store'
ModelsForSync = [
'threads',
'messages',
'labels',
'folders',
'drafts',
'contacts',
'calendars',
'events'
]
class NylasSyncStatusStore extends NylasStore class NylasSyncStatusStore extends NylasStore
ModelsForSync: ModelsForSync
constructor: -> constructor: ->
@_statesByAccount = {} @_statesByAccount = {}
@ -29,12 +41,13 @@ class NylasSyncStatusStore extends NylasStore
return false unless @_statesByAccount[acctId] return false unless @_statesByAccount[acctId]
if model if model
return @_statesByAccount[acctId][model]?.complete ? false return @_statesByAccount[acctId][model]?.complete ? false
for _model, modelState of @_statesByAccount[acctId] for _model in ModelsForSync
continue if _model in ['longConnectionStatus', 'nextRetryTimestamp'] modelState = @_statesByAccount[_model]
return false if not modelState.complete return false if not modelState?.complete
return true return true
isSyncComplete: => isSyncComplete: =>
return false if _.isEmpty(@_statesByAccount)
for acctId of @_statesByAccount for acctId of @_statesByAccount
return false if not @isSyncCompleteForAccount(acctId) return false if not @isSyncCompleteForAccount(acctId)
return true return true