mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-08 21:55:54 +08:00
fix(inbox): refetch labels and folders if the "inbox" label missing
Summary: Fixes T3559 Test Plan: new tests Reviewers: bengotow, dillon Reviewed By: dillon Maniphest Tasks: T3559 Differential Revision: https://phab.nylas.com/D2052
This commit is contained in:
parent
213bbde692
commit
1f4902660b
2 changed files with 40 additions and 3 deletions
|
@ -137,11 +137,14 @@ class NylasSyncWorker
|
|||
requestOptions =
|
||||
error: (err) =>
|
||||
return if @_terminated
|
||||
@_resumeTimer.backoff()
|
||||
@_resumeTimer.start()
|
||||
@updateTransferState(model, {busy: false, complete: false, error: err.toString()})
|
||||
@_fetchCollectionPageError(model, err)
|
||||
success: (json) =>
|
||||
return if @_terminated
|
||||
|
||||
if model in ["labels", "folders"] and @_hasNoInbox(json)
|
||||
@_fetchCollectionPageError(model, "No inbox in #{model}")
|
||||
return
|
||||
|
||||
lastReceivedIndex = params.offset + json.length
|
||||
if json.length is params.limit
|
||||
nextParams = _.extend({}, params, {offset: lastReceivedIndex})
|
||||
|
@ -156,6 +159,18 @@ class NylasSyncWorker
|
|||
else
|
||||
@_api.getCollection(@_account.id, model, params, requestOptions)
|
||||
|
||||
# It's occasionally possible for the NylasAPI's labels or folders
|
||||
# endpoint to not return an "inbox" label. Since that's a core part of
|
||||
# the app and it doesn't function without it, keep retrying until we see
|
||||
# it.
|
||||
_hasNoInbox: (json) ->
|
||||
return not _.any(json, (obj) -> obj.name is "inbox")
|
||||
|
||||
_fetchCollectionPageError: (model, err) ->
|
||||
@_resumeTimer.backoff()
|
||||
@_resumeTimer.start()
|
||||
@updateTransferState(model, {busy: false, complete: false, error: err.toString()})
|
||||
|
||||
updateTransferState: (model, {busy, error, complete, fetched, count}) ->
|
||||
@_state[model] = _.defaults({busy, error, complete, fetched, count}, @_state[model])
|
||||
@writeState()
|
||||
|
|
|
@ -101,6 +101,28 @@ describe "NylasSyncWorker", ->
|
|||
advanceClock(30000); expect(@worker.resumeFetches.callCount).toBe(4)
|
||||
advanceClock(30000); expect(@worker.resumeFetches.callCount).toBe(5)
|
||||
|
||||
it "handles the request as a failure if we try and grab labels or folders without an 'inbox'", ->
|
||||
|
||||
spyOn(@worker, 'resumeFetches').andCallThrough()
|
||||
@worker.start()
|
||||
expect(@worker.resumeFetches.callCount).toBe(1)
|
||||
request = _.findWhere(@apiRequests, model: 'labels')
|
||||
request.requestOptions.success([])
|
||||
expect(@worker.resumeFetches.callCount).toBe(1)
|
||||
advanceClock(30000)
|
||||
expect(@worker.resumeFetches.callCount).toBe(2)
|
||||
|
||||
it "handles the request as a success if we try and grab labels or folders and it includes the 'inbox'", ->
|
||||
|
||||
spyOn(@worker, 'resumeFetches').andCallThrough()
|
||||
@worker.start()
|
||||
expect(@worker.resumeFetches.callCount).toBe(1)
|
||||
request = _.findWhere(@apiRequests, model: 'labels')
|
||||
request.requestOptions.success([{name: "inbox"}, {name: "archive"}])
|
||||
expect(@worker.resumeFetches.callCount).toBe(1)
|
||||
advanceClock(30000)
|
||||
expect(@worker.resumeFetches.callCount).toBe(1)
|
||||
|
||||
describe "when a count request completes", ->
|
||||
beforeEach ->
|
||||
@worker.start()
|
||||
|
|
Loading…
Add table
Reference in a new issue