FEATURE: add Unseen view (#13977)

This view is the same as Latest except it hides the topics you have fully read. Based on this plugin of @davidtaylorhq https://meta.discourse.org/t/simple-unread-list-plugin-discourse-simple-unread/70013.
This commit is contained in:
Andrei Prigorshnev
2021-08-10 18:30:34 +04:00
committed by GitHub
parent d54b339809
commit 622859dbe6
5 changed files with 100 additions and 12 deletions

View File

@@ -62,7 +62,7 @@ describe TopicQuery do
end
end
context "list_topics_by" do
context "#list_topics_by" do
it "allows users to view their own invisible topics" do
_topic = Fabricate(:topic, user: user)
@@ -74,7 +74,7 @@ describe TopicQuery do
end
context "prioritize_pinned_topics" do
context "#prioritize_pinned_topics" do
it "does the pagination correctly" do
num_topics = 15
per_page = 3
@@ -730,7 +730,7 @@ describe TopicQuery do
end
context 'list_new' do
context '#list_new' do
context 'without a new topic' do
it "has no new topics" do
@@ -807,7 +807,7 @@ describe TopicQuery do
end
context 'list_posted' do
context '#list_posted' do
let(:topics) { topic_query.list_posted.topics }
it "returns blank when there are no posted topics" do
@@ -861,7 +861,58 @@ describe TopicQuery do
end
end
context 'list_related_for do' do
context '#list_unseen' do
it "returns an empty list when there aren't topics" do
expect(topic_query.list_unseen.topics).to be_blank
end
it "doesn't return topics that were bumped last time before user joined the forum" do
user.first_seen_at = 10.minutes.ago
create_topic_with_three_posts(bumped_at: 15.minutes.ago)
expect(topic_query.list_unseen.topics).to be_blank
end
it "returns only topics that contain unseen posts" do
user.first_seen_at = 10.minutes.ago
topic_with_unseen_posts = create_topic_with_three_posts(bumped_at: 5.minutes.ago)
read_to_post(topic_with_unseen_posts, user, 1)
fully_read_topic = create_topic_with_three_posts(bumped_at: 5.minutes.ago)
read_to_the_end(fully_read_topic, user)
expect(topic_query.list_unseen.topics).to eq([topic_with_unseen_posts])
end
it "ignores staff posts if user is not staff" do
user.first_seen_at = 10.minutes.ago
topic = create_topic_with_three_posts(bumped_at: 5.minutes.ago)
read_to_the_end(topic, user)
create_post(topic: topic, post_type: Post.types[:whisper])
expect(topic_query.list_unseen.topics).to be_blank
end
def create_topic_with_three_posts(bumped_at:)
topic = Fabricate(:topic, bumped_at: bumped_at)
Fabricate(:post, topic: topic)
Fabricate(:post, topic: topic)
Fabricate(:post, topic: topic)
topic.highest_staff_post_number = 3
topic.highest_post_number = 3
topic
end
def read_to_post(topic, user, post_number)
TopicUser.update_last_read(user, topic.id, post_number, 0, 0)
end
def read_to_the_end(topic, user)
read_to_post topic, user, topic.highest_post_number
end
end
context '#list_related_for' do
let(:user) do
Fabricate(:admin)