From c92818ae5f54d2f0a59bbd0b838138747ebfb768 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 9 Sep 2021 10:59:39 +0800 Subject: [PATCH] FIX: Remove dismiss read topics from PM topic tracking state. (#14287) Follow-up to fc1fd1b41689694b3916dc4e10605eb9b8bb89b7 --- .../discourse/app/mixins/bulk-topic-selection.js | 6 +++++- .../models/private-message-topic-tracking-state.js | 9 +++++++++ .../tests/acceptance/user-private-messages-test.js | 14 +++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/mixins/bulk-topic-selection.js b/app/assets/javascripts/discourse/app/mixins/bulk-topic-selection.js index edcae9b7f32..64489d43845 100644 --- a/app/assets/javascripts/discourse/app/mixins/bulk-topic-selection.js +++ b/app/assets/javascripts/discourse/app/mixins/bulk-topic-selection.js @@ -51,7 +51,11 @@ export default Mixin.create({ promise.then((result) => { if (result && result.topic_ids) { - this.topicTrackingState.removeTopics(result.topic_ids); + if (options.private_message_inbox) { + this.pmTopicTrackingState.removeTopics(result.topic_ids); + } else { + this.topicTrackingState.removeTopics(result.topic_ids); + } } this.send("closeModal"); diff --git a/app/assets/javascripts/discourse/app/models/private-message-topic-tracking-state.js b/app/assets/javascripts/discourse/app/models/private-message-topic-tracking-state.js index 83ca813d8e6..c8a8d0fcb44 100644 --- a/app/assets/javascripts/discourse/app/models/private-message-topic-tracking-state.js +++ b/app/assets/javascripts/discourse/app/models/private-message-topic-tracking-state.js @@ -81,6 +81,15 @@ const PrivateMessageTopicTrackingState = EmberObject.extend({ } }, + removeTopics(topicIds) { + if (!this.isTracking) { + return; + } + + topicIds.forEach((topicId) => this.states.delete(topicId)); + this.incrementProperty("statesModificationCounter"); + }, + _userChannel() { return `${this.CHANNEL_PREFIX}/user/${this.currentUser.id}`; }, diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js index be77c5625ef..20b95127dba 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js @@ -166,7 +166,9 @@ acceptance( fetchUserNew = true; } - return helper.response({}); + return helper.response({ + topic_ids: [1, 2, 3], + }); }); }); @@ -459,6 +461,10 @@ acceptance( test("dismissing all unread messages", async function (assert) { await visit("/u/charlie/messages/unread"); + publishUnreadToMessageBus({ topicId: 1, userId: 5 }); + publishUnreadToMessageBus({ topicId: 2, userId: 5 }); + publishUnreadToMessageBus({ topicId: 3, userId: 5 }); + assert.equal( count(".topic-list-item"), 3, @@ -468,6 +474,12 @@ acceptance( await click(".btn.dismiss-read"); await click("#dismiss-read-confirm"); + assert.equal( + query(".messages-nav li a.unread").innerText.trim(), + I18n.t("user.messages.unread"), + "displays the right count" + ); + assert.equal( count(".topic-list-item"), 0,