From 47623e1214f525057ae4136ffc6e31ce0787d1f6 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Wed, 21 Feb 2024 20:08:47 +0200 Subject: [PATCH] FIX: Ensure model properties are set (#25790) New models do not have all properties set yet which caused issues when trying to access them. --- app/assets/javascripts/discourse/app/models/group.js | 5 +++++ app/assets/javascripts/discourse/app/models/user.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/app/assets/javascripts/discourse/app/models/group.js b/app/assets/javascripts/discourse/app/models/group.js index 220c131f446..9ae1df34713 100644 --- a/app/assets/javascripts/discourse/app/models/group.js +++ b/app/assets/javascripts/discourse/app/models/group.js @@ -223,6 +223,7 @@ export default class Group extends RestModel { get watchingCategories() { if ( this.site.lazy_load_categories && + this.watching_category_ids && !Category.hasAsyncFoundAll(this.watching_category_ids) ) { Category.asyncFindByIds(this.watching_category_ids).then(() => @@ -244,6 +245,7 @@ export default class Group extends RestModel { get trackingCategories() { if ( this.site.lazy_load_categories && + this.tracking_category_ids && !Category.hasAsyncFoundAll(this.tracking_category_ids) ) { Category.asyncFindByIds(this.tracking_category_ids).then(() => @@ -265,6 +267,7 @@ export default class Group extends RestModel { get watchingFirstPostCategories() { if ( this.site.lazy_load_categories && + this.watching_first_post_category_ids && !Category.hasAsyncFoundAll(this.watching_first_post_category_ids) ) { Category.asyncFindByIds(this.watching_first_post_category_ids).then(() => @@ -286,6 +289,7 @@ export default class Group extends RestModel { get regularCategories() { if ( this.site.lazy_load_categories && + this.regular_category_ids && !Category.hasAsyncFoundAll(this.regular_category_ids) ) { Category.asyncFindByIds(this.regular_category_ids).then(() => @@ -307,6 +311,7 @@ export default class Group extends RestModel { get mutedCategories() { if ( this.site.lazy_load_categories && + this.muted_category_ids && !Category.hasAsyncFoundAll(this.muted_category_ids) ) { Category.asyncFindByIds(this.muted_category_ids).then(() => diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js index 11721e59bbd..f3c9f7f590f 100644 --- a/app/assets/javascripts/discourse/app/models/user.js +++ b/app/assets/javascripts/discourse/app/models/user.js @@ -845,6 +845,7 @@ export default class User extends RestModel.extend(Evented) { get mutedCategories() { if ( this.site.lazy_load_categories && + this.muted_category_ids && !Category.hasAsyncFoundAll(this.muted_category_ids) ) { Category.asyncFindByIds(this.muted_category_ids).then(() => @@ -866,6 +867,7 @@ export default class User extends RestModel.extend(Evented) { get regularCategories() { if ( this.site.lazy_load_categories && + this.regular_category_ids && !Category.hasAsyncFoundAll(this.regular_category_ids) ) { Category.asyncFindByIds(this.regular_category_ids).then(() => @@ -887,6 +889,7 @@ export default class User extends RestModel.extend(Evented) { get trackedCategories() { if ( this.site.lazy_load_categories && + this.tracked_category_ids && !Category.hasAsyncFoundAll(this.tracked_category_ids) ) { Category.asyncFindByIds(this.tracked_category_ids).then(() => @@ -908,6 +911,7 @@ export default class User extends RestModel.extend(Evented) { get watchedCategories() { if ( this.site.lazy_load_categories && + this.watched_category_ids && !Category.hasAsyncFoundAll(this.watched_category_ids) ) { Category.asyncFindByIds(this.watched_category_ids).then(() => @@ -929,6 +933,7 @@ export default class User extends RestModel.extend(Evented) { get watchedFirstPostCategories() { if ( this.site.lazy_load_categories && + this.watched_first_post_category_ids && !Category.hasAsyncFoundAll(this.watched_first_post_category_ids) ) { Category.asyncFindByIds(this.watched_first_post_category_ids).then(() =>