FEATURE: don't display new/unread notification for muted topics (#9482)

* FEATURE: don't display new/unread notification for muted topics

Currently, even if user mute topic, when a new reply to that topic arrives, the user will get "See 1 new or updated topic" message. After clicking on that link, nothing is visible (because the topic is muted)

To solve that problem, we will send background message to all users who recently muted that topic that update is coming and they can ignore the next message about that topic.
This commit is contained in:
Krzysztof Kotlarek
2020-04-23 14:57:35 +10:00
committed by GitHub
parent 54ec9f7009
commit 52c1d7337e
5 changed files with 125 additions and 2 deletions

View File

@ -2,8 +2,17 @@ import TopicTrackingState from "discourse/models/topic-tracking-state";
import createStore from "helpers/create-store";
import Category from "discourse/models/category";
import { NotificationLevels } from "discourse/lib/notification-levels";
import User from "discourse/models/user";
QUnit.module("model:topic-tracking-state");
QUnit.module("model:topic-tracking-state", {
beforeEach() {
this.clock = sinon.useFakeTimers(new Date(2012, 11, 31, 12, 0).getTime());
},
afterEach() {
this.clock.restore();
}
});
QUnit.test("sync", function(assert) {
const state = TopicTrackingState.create();
@ -168,3 +177,22 @@ QUnit.test("countNew", assert => {
assert.equal(state.countNew(2), 2);
assert.equal(state.countNew(3), 1);
});
QUnit.test("mute topic", function(assert) {
let currentUser = User.create({
username: "chuck",
muted_category_ids: []
});
const state = TopicTrackingState.create({ currentUser });
state.trackMutedTopic(1);
assert.equal(currentUser.muted_topics[0].topicId, 1);
state.pruneOldMutedTopics();
assert.equal(state.isMutedTopic(1), true);
this.clock.tick(60000);
state.pruneOldMutedTopics();
assert.equal(state.isMutedTopic(1), false);
});