From 69861049f006b2d953f7d5745ac670715848fcf2 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Wed, 23 Nov 2016 17:08:38 -0800 Subject: [PATCH] fix(thread): handles new API with both folders and labels --- src/flux/models/thread.es6 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/flux/models/thread.es6 b/src/flux/models/thread.es6 index ec2fdbe46..34433324a 100644 --- a/src/flux/models/thread.es6 +++ b/src/flux/models/thread.es6 @@ -200,6 +200,13 @@ class Thread extends ModelWithMetadata { return true } + /** + * In the `clone` case, there are `categories` set, but no `folders` nor + * `labels` + * + * When loading data from the API, there are `folders` AND `labels` but + * no `categories` yet. + */ fromJSON(json) { super.fromJSON(json) @@ -210,10 +217,11 @@ class Thread extends ModelWithMetadata { if (json.labels) { this.categoriesType = 'labels' - this.categories = Thread.attributes.categories.fromJSON(json.labels) + if (!this.categories) this.categories = []; + this.categories = this.categories.concat(Thread.attributes.categories.fromJSON(json.labels)) } - ['participants', 'categories'].forEach((attr) => { + ['participants'].forEach((attr) => { const value = this[attr] if (!(value && value instanceof Array)) { return;