From ee8c943326ca09e269601e3317b0b166f70dffc3 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 9 Sep 2021 12:39:27 +0800 Subject: [PATCH] FIX: Remove dismissed new topics from PM topic tracking state. (#14288) Follow-up to fc1fd1b41689694b3916dc4e10605eb9b8bb89b7 --- .../discourse/app/controllers/user-topics-list.js | 7 +++++-- .../tests/acceptance/user-private-messages-test.js | 12 +++++++++++- app/controllers/topics_controller.rb | 4 ++-- spec/requests/topics_controller_spec.rb | 5 +++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/user-topics-list.js b/app/assets/javascripts/discourse/app/controllers/user-topics-list.js index 7e95ed10997..55a9f771981 100644 --- a/app/assets/javascripts/discourse/app/controllers/user-topics-list.js +++ b/app/assets/javascripts/discourse/app/controllers/user-topics-list.js @@ -67,8 +67,11 @@ export default Controller.extend(BulkTopicSelection, { opts.groupName = this.group.name; } - Topic.pmResetNew(opts).then(() => { - this.send("refresh"); + Topic.pmResetNew(opts).then((result) => { + if (result && result.topic_ids.length > 0) { + this.pmTopicTrackingState.removeTopics(result.topic_ids); + this.send("refresh"); + } }); }, 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 20b95127dba..c41e7e4e9ed 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 @@ -144,7 +144,7 @@ acceptance( fetchedNew = true; } - return helper.response({}); + return helper.response({ topic_ids: [1, 2, 3] }); }); server.put("/topics/bulk", (request) => { @@ -528,6 +528,10 @@ acceptance( test("dismissing all new messages", async function (assert) { await visit("/u/charlie/messages/new"); + publishNewToMessageBus({ topicId: 1, userId: 5 }); + publishNewToMessageBus({ topicId: 2, userId: 5 }); + publishNewToMessageBus({ topicId: 3, userId: 5 }); + assert.equal( count(".topic-list-item"), 3, @@ -536,6 +540,12 @@ acceptance( await click(".btn.dismiss-read"); + assert.equal( + query(".messages-nav li a.new").innerText.trim(), + I18n.t("user.messages.new"), + "displays the right count" + ); + assert.equal( count(".topic-list-item"), 0, diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index f0a2a562d7d..1f9ab77c30f 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -962,13 +962,13 @@ class TopicsController < ApplicationController topic_scope = topic_query.filter_private_message_new(current_user, filter) end - TopicsBulkAction.new( + topic_ids = TopicsBulkAction.new( current_user, topic_scope.pluck(:id), type: "dismiss_topics" ).perform! - render json: success_json + render json: success_json.merge(topic_ids: topic_ids) end def reset_new diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 76e3711f750..6cd81254d66 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -4383,6 +4383,7 @@ RSpec.describe TopicsController do } expect(response.status).to eq(200) + expect(response.parsed_body["topic_ids"]).to contain_exactly(group_message.id) expect(DismissedTopicUser.count).to eq(1) @@ -4396,6 +4397,10 @@ RSpec.describe TopicsController do } expect(response.status).to eq(200) + expect(response.parsed_body["topic_ids"]).to contain_exactly( + private_message.id, + private_message_2.id + ) expect(DismissedTopicUser.count).to eq(2)