diff --git a/app/models/topic.rb b/app/models/topic.rb index 93365f66994..3794e7ac3b4 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -362,7 +362,7 @@ class Topic < ActiveRecord::Base topics = topics.where("topics.category_id NOT IN (?)", muted_category_ids) end - # Remove muted categories + # Remove muted tags muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id) unless muted_tag_ids.empty? topics = topics.joins("LEFT OUTER JOIN topic_tags ON topic_tags.topic_id = topics.id") diff --git a/lib/topic_query_sql.rb b/lib/topic_query_sql.rb index 003c0000c6a..2f9bbe59930 100644 --- a/lib/topic_query_sql.rb +++ b/lib/topic_query_sql.rb @@ -52,7 +52,7 @@ module TopicQuerySQL end def order_top_with_notification_levels(score) - "COALESCE(category_users.notification_level, 1) DESC, COALESCE(top_topics.#{score}, 0) DESC, topics.bumped_at DESC" + "COALESCE(topic_users.notification_level, 1) DESC, COALESCE(category_users.notification_level, 1) DESC, COALESCE(top_topics.#{score}, 0) DESC, topics.bumped_at DESC" end end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 1869cb233ae..6b84eff2e65 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1392,6 +1392,16 @@ describe Topic do expect(for_digest.first).to eq(topic1) end + it "sorts by topic notification levels" do + topics = [] + 3.times {|i| topics << Fabricate(:topic) } + user = Fabricate(:user) + TopicUser.create(user_id: user.id, topic_id: topics[0].id, notification_level: TopicUser.notification_levels[:tracking]) + TopicUser.create(user_id: user.id, topic_id: topics[2].id, notification_level: TopicUser.notification_levels[:watching]) + for_digest = Topic.for_digest(user, 1.year.ago, top_order: true).pluck(:id) + expect(for_digest).to eq([topics[2].id, topics[0].id, topics[1].id]) + end + end describe 'secured' do