FIX: Remove dismissed new topics from PM topic tracking state. (#14288)

Follow-up to fc1fd1b416
This commit is contained in:
Alan Guo Xiang Tan 2021-09-09 12:39:27 +08:00 committed by GitHub
parent c92818ae5f
commit ee8c943326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 5 deletions

View File

@ -67,8 +67,11 @@ export default Controller.extend(BulkTopicSelection, {
opts.groupName = this.group.name;
}
Topic.pmResetNew(opts).then(() => {
Topic.pmResetNew(opts).then((result) => {
if (result && result.topic_ids.length > 0) {
this.pmTopicTrackingState.removeTopics(result.topic_ids);
this.send("refresh");
}
});
},

View File

@ -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,

View File

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

View File

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