fix(window): fix error when adding account and serializing bad API data

This commit is contained in:
Evan Morikawa 2016-05-03 11:30:41 -07:00
parent 5add83b467
commit c89413e98d
4 changed files with 17 additions and 5 deletions

View file

@ -132,6 +132,14 @@ class SidebarItem
@forUnread: (accountIds, opts = {}) ->
categories = accountIds.map (accId) =>
CategoryStore.getStandardCategory(accId, 'inbox')
# NOTE: It's possible for an account to not yet have an `inbox`
# category. Since the `SidebarStore` triggers on `AccountStore`
# changes, it'll trigger the exact moment an account is added to the
# config. However, the API has not yet come back with the list of
# `categories` for that account.
categories = _.compact(categories)
perspective = MailboxPerspective.forUnread(categories)
id = 'Unread'
id += "-#{opts.name}" if opts.name

View file

@ -223,7 +223,7 @@ class Application
title: "Welcome to N1"
windowProps: page: "welcome"
})
# The onboarding window automatically shows when it's ready
@windowManager.ensureWindow(WindowManager.WORK_WINDOW)
_resetConfigAndRelaunch: =>
@setDatabasePhase('close')
@ -232,10 +232,7 @@ class Application
@config.set('nylas', null)
@config.set('edgehill', null)
@setDatabasePhase('setup')
@windowManager.ensureWindow(WindowManager.ONBOARDING_WINDOW, {
title: "Welcome to N1"
windowProps: page: "welcome"
})
@openWindowsForTokenState()
_deleteDatabase: (callback) ->
@deleteFileWithRetry path.join(@configDirPath,'edgehill.db'), callback

View file

@ -55,6 +55,12 @@ class AttributeCollection extends Attribute
fromJSON: (json) ->
return [] unless json && json instanceof Array
objs = []
# Note: It's possible for a malformed API request to return an array
# of null values. N1 is tolerant to this type of error, but shouldn't
# happen on the API end.
json = _.compact(json)
for objJSON in json
if @itemClass.prototype.fromJSON?
obj = new @itemClass

View file

@ -46,6 +46,7 @@ class MailboxPerspective
new StarredMailboxPerspective(accountsOrIds)
@forUnread: (categories) ->
return @forNothing() if categories.length is 0
new UnreadMailboxPerspective(categories)
@forInbox: (accountsOrIds) =>