fix(Message): update fromJSON()

Summary:
- Handle `categories` if it exists, because clone() will call fromJSON()
    on the results of toJSON(), which populates `categories` instead of
    `folder` or `labels`
- Remove the else-if for `folder` and `labels`, because both can co-exist.
    Also concatenate the results from these two, rathering than overwriting.

Submodule commit is D3581, these two diffs together help make sure the
inflated messages in N1 have the right categories.

Test Plan: tested locally

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3582
This commit is contained in:
Halla Moore 2017-01-04 15:56:35 -08:00
parent bf9dfa3727
commit 21db84f13f
2 changed files with 12 additions and 5 deletions

2
src/K2

@ -1 +1 @@
Subproject commit 09f19d1adfec03c99fae0b4a1610b6c51e47f491
Subproject commit 3336479d5dd1140dc18783ea1d0bb91081a5885a

View file

@ -228,11 +228,18 @@ Message(date DESC) WHERE draft = 1`,
this.draft = (json.object === 'draft')
}
let categories = []
if (json.categories) {
categories = this.constructor.attributes.categories.fromJSON(json.categories)
} else {
if (json.folder) {
this.categories = this.constructor.attributes.categories.fromJSON([json.folder])
} else if (json.labels) {
this.categories = this.constructor.attributes.categories.fromJSON(json.labels)
categories = categories.concat(this.constructor.attributes.categories.fromJSON([json.folder]))
}
if (json.labels) {
categories = categories.concat(this.constructor.attributes.categories.fromJSON(json.labels))
}
}
this.categories = categories
for (const attr of ['to', 'from', 'cc', 'bcc', 'files', 'categories']) {
const values = this[attr]