Skip to content

Commit

Permalink
FIX: new topic indicator on the mobile categories page (#12271)
Browse files Browse the repository at this point in the history
Regression with new dismiss button. We need the same solution to indicate if the topic was seen for category_list as done for topic_list:
https://github.com/discourse/discourse/blob/master/app/models/topic_list.rb#L123

Meta: https://meta.discourse.org/t/dismissed-new-topics-still-show-blue-dots-in-categories-view/181596
  • Loading branch information
lis2 committed Mar 4, 2021
1 parent 9f474b1 commit e076506
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions app/models/category_list.rb
Expand Up @@ -66,6 +66,7 @@ def find_relevant_topics
@all_topics.each do |t|
# hint for the serializer
t.include_last_poster = true if @options[:include_topics]
t.dismissed = dismissed_topic?(t)
@topics_by_id[t.id] = t
end

Expand All @@ -75,6 +76,15 @@ def find_relevant_topics
end
end

def dismissed_topic?(topic)
if @guardian.current_user
@dismissed_topic_users_lookup ||= DismissedTopicUser.lookup_for(@guardian.current_user, @all_topics)
@dismissed_topic_users_lookup.include?(topic.id)
else
false
end
end

def find_categories
@categories = Category.includes(
:uploaded_background,
Expand Down
10 changes: 7 additions & 3 deletions spec/models/category_list_spec.rb
Expand Up @@ -95,18 +95,22 @@
let!(:topic2) { Fabricate(:topic, category: topic_category, bumped_at: 5.minutes.ago) }
let!(:topic3) { Fabricate(:topic, category: topic_category, bumped_at: 2.minutes.ago) }
let!(:pinned) { Fabricate(:topic, category: topic_category, pinned_at: 10.minutes.ago, bumped_at: 10.minutes.ago) }
let!(:dismissed_topic_user) { Fabricate(:dismissed_topic_user, topic: topic2, user: user) }

def displayable_topics
category_list = CategoryList.new(Guardian.new(user), include_topics: true)
category_list.categories.find { |c| c.id == topic_category.id }.displayable_topics.map(&:id)
category_list.categories.find { |c| c.id == topic_category.id }.displayable_topics
end

it "returns pinned topic first" do
expect(displayable_topics).to eq([pinned.id, topic3.id])
expect(displayable_topics.map(&:id)).to eq([pinned.id, topic3.id])

TopicUser.change(user.id, pinned.id, cleared_pinned_at: pinned.pinned_at + 10)

expect(displayable_topics).to eq([topic3.id, topic2.id])
expect(displayable_topics[0].dismissed).to eq(false)
expect(displayable_topics[1].dismissed).to eq(true)

expect(displayable_topics.map(&:id)).to eq([topic3.id, topic2.id])
end
end

Expand Down

1 comment on commit e076506

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/dismissed-new-topics-still-show-blue-dots-in-categories-view/181596/4

Please sign in to comment.