mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
FEATURE: new dismiss button for combined new and unread view (#21817)
Display modal for combined new and unread view with options: - [x] Dismiss new topics - [x] Dismiss new posts - [ ] Stop tracking these topics so they stop appearing in my new list
This commit is contained in:

committed by
GitHub

parent
899969fd5d
commit
af74cf5c77
@ -4061,6 +4061,168 @@ RSpec.describe TopicsController do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "new and unread" do
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
fab!(:new_topic) { Fabricate(:topic) }
|
||||
fab!(:unread_topic) { Fabricate(:topic, highest_post_number: 3) }
|
||||
fab!(:topic_user) do
|
||||
Fabricate(
|
||||
:topic_user,
|
||||
topic: unread_topic,
|
||||
user: user,
|
||||
notification_level: NotificationLevels.topic_levels[:tracking],
|
||||
last_read_post_number: 1,
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
create_post(topic: unread_topic)
|
||||
create_post(topic: unread_topic)
|
||||
user.groups << group
|
||||
SiteSetting.experimental_new_new_view_groups = group.id
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
it "dismisses new topics" do
|
||||
put "/topics/reset-new.json"
|
||||
topics = TopicQuery.new(user).new_and_unread_results(limit: false)
|
||||
expect(topics).to eq([unread_topic, new_topic])
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_ids"]).to eq([])
|
||||
|
||||
put "/topics/reset-new.json", params: { dismiss_topics: true }
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_ids"]).to eq([new_topic.id])
|
||||
|
||||
topics = TopicQuery.new(user).new_and_unread_results(limit: false)
|
||||
expect(topics).to eq([unread_topic])
|
||||
expect(DismissedTopicUser.where(user: user).count).to eq(1)
|
||||
expect(DismissedTopicUser.where(user: user).first.topic_id).to eq(new_topic.id)
|
||||
expect(topic_user.reload.notification_level).to eq(
|
||||
NotificationLevels.topic_levels[:tracking],
|
||||
)
|
||||
end
|
||||
|
||||
it "dismisses unread topics" do
|
||||
put "/topics/reset-new.json"
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_ids"]).to eq([])
|
||||
topics = TopicQuery.new(user).new_and_unread_results(limit: false)
|
||||
expect(topics).to eq([unread_topic, new_topic])
|
||||
|
||||
put "/topics/reset-new.json", params: { dismiss_posts: true }
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_ids"]).to eq([unread_topic.id])
|
||||
|
||||
topics = TopicQuery.new(user).new_and_unread_results(limit: false)
|
||||
expect(topics).to eq([new_topic])
|
||||
expect(DismissedTopicUser.count).to eq(0)
|
||||
expect(topic_user.reload.notification_level).to eq(
|
||||
NotificationLevels.topic_levels[:tracking],
|
||||
)
|
||||
end
|
||||
|
||||
it "untrack topics" do
|
||||
expect(topic_user.notification_level).to eq(NotificationLevels.topic_levels[:tracking])
|
||||
put "/topics/reset-new.json", params: { dismiss_posts: true, untrack: true }
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_ids"]).to eq([unread_topic.id])
|
||||
|
||||
expect(topic_user.reload.notification_level).to eq(
|
||||
NotificationLevels.topic_levels[:regular],
|
||||
)
|
||||
end
|
||||
|
||||
it "dismisses new topics, unread posts and untrack" do
|
||||
put "/topics/reset-new.json",
|
||||
params: {
|
||||
dismiss_topics: true,
|
||||
dismiss_posts: true,
|
||||
untrack: true,
|
||||
}
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_ids"]).to eq([new_topic.id, unread_topic.id])
|
||||
|
||||
topics = TopicQuery.new(user).new_and_unread_results(limit: false)
|
||||
expect(topics).to be_empty
|
||||
expect(DismissedTopicUser.where(user: user).count).to eq(1)
|
||||
expect(DismissedTopicUser.where(user: user).first.topic_id).to eq(new_topic.id)
|
||||
|
||||
expect(user.topic_users.map(&:notification_level).uniq).to eq(
|
||||
[NotificationLevels.topic_levels[:regular]],
|
||||
)
|
||||
end
|
||||
|
||||
context "when category" do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:new_topic_2) { Fabricate(:topic, category: category) }
|
||||
fab!(:unread_topic_2) { Fabricate(:topic, category: category, highest_post_number: 3) }
|
||||
fab!(:topic_user) do
|
||||
Fabricate(
|
||||
:topic_user,
|
||||
topic: unread_topic_2,
|
||||
user: user,
|
||||
notification_level: NotificationLevels.topic_levels[:tracking],
|
||||
last_read_post_number: 1,
|
||||
)
|
||||
end
|
||||
|
||||
it "dismisses new topics, unread posts and untrack for specific category" do
|
||||
topics = TopicQuery.new(user).new_and_unread_results(limit: false)
|
||||
expect(topics).to match_array([new_topic, new_topic_2, unread_topic, unread_topic_2])
|
||||
|
||||
put "/topics/reset-new.json",
|
||||
params: {
|
||||
dismiss_topics: true,
|
||||
dismiss_posts: true,
|
||||
untrack: true,
|
||||
category_id: category.id,
|
||||
}
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_ids"]).to eq([new_topic_2.id, unread_topic_2.id])
|
||||
|
||||
topics = TopicQuery.new(user).new_and_unread_results(limit: false)
|
||||
expect(topics).to match_array([new_topic, unread_topic])
|
||||
end
|
||||
end
|
||||
|
||||
context "when tag" do
|
||||
fab!(:tag) { Fabricate(:tag) }
|
||||
fab!(:new_topic_2) { Fabricate(:topic) }
|
||||
fab!(:unread_topic_2) { Fabricate(:topic, highest_post_number: 3) }
|
||||
fab!(:topic_user) do
|
||||
Fabricate(
|
||||
:topic_user,
|
||||
topic: unread_topic_2,
|
||||
user: user,
|
||||
notification_level: NotificationLevels.topic_levels[:tracking],
|
||||
last_read_post_number: 1,
|
||||
)
|
||||
end
|
||||
fab!(:topic_tag) { Fabricate(:topic_tag, topic: new_topic_2, tag: tag) }
|
||||
fab!(:topic_tag_2) { Fabricate(:topic_tag, topic: unread_topic_2, tag: tag) }
|
||||
|
||||
it "dismisses new topics, unread posts and untrack for specific tag" do
|
||||
topics = TopicQuery.new(user).new_and_unread_results(limit: false)
|
||||
expect(topics).to match_array([new_topic, new_topic_2, unread_topic, unread_topic_2])
|
||||
|
||||
put "/topics/reset-new.json",
|
||||
params: {
|
||||
dismiss_topics: true,
|
||||
dismiss_posts: true,
|
||||
untrack: true,
|
||||
tag_id: tag.name,
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_ids"]).to eq([new_topic_2.id, unread_topic_2.id])
|
||||
|
||||
topics = TopicQuery.new(user).new_and_unread_results(limit: false)
|
||||
expect(topics).to match_array([new_topic, unread_topic])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#feature_stats" do
|
||||
|
Reference in New Issue
Block a user