FIX: new indirectly muted category (#16043)

When a new category is created and the parent category is muted or indirectly muted, the new category should be indirectly muted as well.
This commit is contained in:
Krzysztof Kotlarek 2022-02-25 13:08:22 +11:00 committed by GitHub
parent c71afdfdb0
commit 3e5fb90ce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions

View File

@ -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)
);

View File

@ -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) {