mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FEATURE: digest emails will try to choose topics from your tracked and watched categories first
This commit is contained in:
parent
f60bfe7550
commit
5849c345cc
3 changed files with 16 additions and 1 deletions
|
@ -325,6 +325,7 @@ class Topic < ActiveRecord::Base
|
|||
.visible
|
||||
.secured(Guardian.new(user))
|
||||
.joins("LEFT OUTER JOIN topic_users ON topic_users.topic_id = topics.id AND topic_users.user_id = #{user.id.to_i}")
|
||||
.joins("LEFT OUTER JOIN category_users ON category_users.category_id = topics.category_id AND category_users.user_id = #{user.id.to_i}")
|
||||
.joins("LEFT OUTER JOIN users ON users.id = topics.user_id")
|
||||
.where(closed: false, archived: false)
|
||||
.where("COALESCE(topic_users.notification_level, 1) <> ?", TopicUser.notification_levels[:muted])
|
||||
|
@ -338,7 +339,7 @@ class Topic < ActiveRecord::Base
|
|||
|
||||
if !!opts[:top_order]
|
||||
topics = topics.joins("LEFT OUTER JOIN top_topics ON top_topics.topic_id = topics.id")
|
||||
.order(TopicQuerySQL.order_top_for(score))
|
||||
.order(TopicQuerySQL.order_top_with_notification_levels(score))
|
||||
end
|
||||
|
||||
if opts[:limit]
|
||||
|
|
|
@ -51,5 +51,9 @@ module TopicQuerySQL
|
|||
topics.bumped_at DESC"
|
||||
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"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1382,6 +1382,16 @@ describe Topic do
|
|||
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic])
|
||||
end
|
||||
|
||||
it "sorts by category notification levels" do
|
||||
category1, category2 = Fabricate(:category), Fabricate(:category)
|
||||
2.times {|i| Fabricate(:topic, category: category1) }
|
||||
topic1 = Fabricate(:topic, category: category2)
|
||||
2.times {|i| Fabricate(:topic, category: category1) }
|
||||
CategoryUser.create(user: user, category: category2, notification_level: CategoryUser.notification_levels[:watching])
|
||||
for_digest = Topic.for_digest(user, 1.year.ago, top_order: true)
|
||||
expect(for_digest.first).to eq(topic1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'secured' do
|
||||
|
|
Loading…
Reference in a new issue