FEATURE: digests choose topics you're watching or tracking first

This commit is contained in:
Neil Lalonde 2016-08-18 17:16:52 -04:00
parent a644602612
commit 7195a103ab
3 changed files with 12 additions and 2 deletions

View File

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

View File

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

View File

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