diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/categories.js b/app/assets/javascripts/discourse/app/controllers/preferences/categories.js
index 16555cdad91..3611af258f9 100644
--- a/app/assets/javascripts/discourse/app/controllers/preferences/categories.js
+++ b/app/assets/javascripts/discourse/app/controllers/preferences/categories.js
@@ -4,26 +4,41 @@ import { or } from "@ember/object/computed";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Controller.extend({
- init() {
- this._super(...arguments);
-
- this.saveAttrNames = [
- "muted_category_ids",
- "regular_category_ids",
+ @discourseComputed("siteSettings.mute_all_categories_by_default")
+ saveAttrNames(muteAllCategoriesByDefault) {
+ return [
"watched_category_ids",
"tracked_category_ids",
"watched_first_post_category_ids",
+ muteAllCategoriesByDefault
+ ? "regular_category_ids"
+ : "muted_category_ids",
];
},
@discourseComputed(
+ "siteSettings.mute_all_categories_by_default",
"model.watchedCategories",
"model.watchedFirstPostCategories",
"model.trackedCategories",
- "model.mutedCategories"
+ "model.mutedCategories",
+ "model.regularCategories"
)
- selectedCategories(watched, watchedFirst, tracked, muted) {
- return [].concat(watched, watchedFirst, tracked, muted).filter((t) => t);
+ selectedCategories(
+ muteAllCategoriesByDefault,
+ watched,
+ watchedFirst,
+ tracked,
+ muted,
+ regular
+ ) {
+ let categories = [].concat(watched, watchedFirst, tracked);
+
+ categories = categories.concat(
+ muteAllCategoriesByDefault ? regular : muted
+ );
+
+ return categories.filter((t) => t);
},
@discourseComputed
diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js
index 80b093c568b..6be7b0398fa 100644
--- a/app/assets/javascripts/discourse/app/models/user.js
+++ b/app/assets/javascripts/discourse/app/models/user.js
@@ -398,22 +398,28 @@ const User = RestModel.extend({
let updatedState = {};
["muted", "regular", "watched", "tracked", "watched_first_post"].forEach(
- (s) => {
- if (fields === undefined || fields.includes(s + "_category_ids")) {
+ (categoryNotificationLevel) => {
+ if (
+ fields === undefined ||
+ fields.includes(`${categoryNotificationLevel}_category_ids`)
+ ) {
let prop =
- s === "watched_first_post"
+ categoryNotificationLevel === "watched_first_post"
? "watchedFirstPostCategories"
- : s + "Categories";
+ : `${categoryNotificationLevel}Categories`;
+
let cats = this.get(prop);
+
if (cats) {
let cat_ids = cats.map((c) => c.get("id"));
- updatedState[s + "_category_ids"] = cat_ids;
+ updatedState[`${categoryNotificationLevel}_category_ids`] = cat_ids;
// HACK: denote lack of categories
if (cats.length === 0) {
cat_ids = [-1];
}
- data[s + "_category_ids"] = cat_ids;
+
+ data[`${categoryNotificationLevel}_category_ids`] = cat_ids;
}
}
}
diff --git a/app/assets/javascripts/discourse/app/templates/preferences/categories.hbs b/app/assets/javascripts/discourse/app/templates/preferences/categories.hbs
index ac28c0b2cec..8a0b2b716b3 100644
--- a/app/assets/javascripts/discourse/app/templates/preferences/categories.hbs
+++ b/app/assets/javascripts/discourse/app/templates/preferences/categories.hbs
@@ -1,7 +1,7 @@
-
+
{{i18n "user.watched_categories_instructions"}}
-
+
{{i18n "user.tracked_categories_instructions"}}
-
+
{{i18n "user.watched_first_post_categories_instructions"}}
{{#if this.siteSettings.mute_all_categories_by_default}}
-
+
{{i18n "user.regular_categories_instructions"}}
{{else}}
-
+
{{#if this.canSee}}
{{i18n "user.tracked_topics_link"}}
diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-categories-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-categories-test.js
new file mode 100644
index 00000000000..2674921aae6
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-categories-test.js
@@ -0,0 +1,75 @@
+import { test } from "qunit";
+import { click, visit } from "@ember/test-helpers";
+import { acceptance } from "discourse/tests/helpers/qunit-helpers";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+
+acceptance("User Preferences - Categories", function (needs) {
+ needs.user();
+
+ let putRequestData;
+
+ needs.pretender((server, helper) => {
+ server.put("/u/eviltrout.json", (request) => {
+ putRequestData = helper.parsePostData(request.requestBody);
+ return helper.response({ user: {} });
+ });
+ });
+
+ needs.hooks.afterEach(() => {
+ putRequestData = null;
+ });
+
+ test("tracking category which is set to regular notification level for user when mute_all_categories_by_default site setting is enabled", async function (assert) {
+ this.siteSettings.mute_all_categories_by_default = true;
+
+ await visit("/u/eviltrout/preferences/categories");
+
+ const trackedCategoriesSelector = selectKit(
+ ".tracking-controls--tracked-categories .category-selector"
+ );
+
+ await trackedCategoriesSelector.expand();
+
+ assert.notOk(
+ trackedCategoriesSelector.rowByValue("4").exists(),
+ "category that is set to regular is not available for selection"
+ );
+
+ const regularCategoriesSelector = selectKit(
+ ".tracking-controls--regular-categories .category-selector"
+ );
+
+ await regularCategoriesSelector.expand();
+ await regularCategoriesSelector.deselectItemByValue("4");
+ await trackedCategoriesSelector.expand();
+ await trackedCategoriesSelector.selectRowByValue("4");
+ await click(".save-changes");
+
+ assert.deepEqual(putRequestData, {
+ "regular_category_ids[]": ["-1"],
+ "tracked_category_ids[]": ["4"],
+ "watched_category_ids[]": ["3"],
+ "watched_first_post_category_ids[]": ["-1"],
+ });
+ });
+
+ test("tracking category which is set to regular notification level for user when mute_all_categories_by_default site setting is disabled", async function (assert) {
+ await visit("/u/eviltrout/preferences/categories");
+
+ const categorySelector = selectKit(
+ ".tracking-controls--tracked-categories .category-selector"
+ );
+
+ await categorySelector.expand();
+ // User has `regular_category_ids` set to [4] in fixtures
+ await categorySelector.selectRowByValue(4);
+ await click(".save-changes");
+
+ assert.deepEqual(putRequestData, {
+ "muted_category_ids[]": ["-1"],
+ "tracked_category_ids[]": ["4"],
+ "watched_category_ids[]": ["3"],
+ "watched_first_post_category_ids[]": ["-1"],
+ });
+ });
+});