Skip to content

A platform for community discussion. Free, open, simple.

FIX: new indirectly muted category (#16043)

Krzysztof Kotlarek3e5fb90ce611
diff --git a/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js b/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js
index 2381e0886e0..dba138be2bf 100644
--- a/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js
+++ b/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js
@@ -117,7 +117,22 @@ export default {
const router = container.lookup("router:main");
bus.subscribe("/categories", (data) => {
- (data.categories || []).forEach((c) => site.updateCategory(c));
+ (data.categories || []).forEach((c) => {
+ const mutedCategoryIds = user.muted_category_ids?.concat(
+ user.indirectly_muted_category_ids
+ );
+ if (
+ mutedCategoryIds &&
+ mutedCategoryIds.includes(c.parent_category_id) &&
+ !mutedCategoryIds.includes(c.id)
+ ) {
+ user.set(
+ "indirectly_muted_category_ids",
+ user.indirectly_muted_category_ids.concat(c.id)
+ );
+ }
+ return site.updateCategory(c);
+ });
(data.deleted_categories || []).forEach((id) =>
site.removeCategory(id)
);
diff --git a/app/assets/javascripts/discourse/tests/acceptance/notifications-test.js b/app/assets/javascripts/discourse/tests/acceptance/notifications-test.js
index 34160f56668..55498b7a879 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/notifications-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/notifications-test.js
@@ -8,6 +8,7 @@ import {
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
+import User from "discourse/models/user";
acceptance("User Notifications", function (needs) {
needs.user();
@@ -197,6 +198,41 @@ acceptance("User Notifications", function (needs) {
});
});
+acceptance("Category Notifications", function (needs) {
+ needs.user({ muted_category_ids: [1], indirectly_muted_category_ids: [2] });
+
+ test("New category is muted when parent category is muted", async function (assert) {
+ await visit("/");
+ const user = User.current();
+ publishToMessageBus("/categories", {
+ categories: [
+ {
+ id: 3,
+ parent_category_id: 99,
+ },
+ {
+ id: 4,
+ },
+ ],
+ });
+ assert.deepEqual(user.indirectly_muted_category_ids, [2]);
+
+ publishToMessageBus("/categories", {
+ categories: [
+ {
+ id: 4,
+ parent_category_id: 1,
+ },
+ {
+ id: 5,
+ parent_category_id: 2,
+ },
+ ],
+ });
+ assert.deepEqual(user.indirectly_muted_category_ids, [2, 4, 5]);
+ });
+});
+
acceptance(
"User Notifications - there is no notifications yet",
function (needs) {