mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 11:19:51 +00:00
Use "Top" logic for digest emails. Leave out muted categories.
This commit is contained in:
parent
2341118570
commit
89aa2380c6
@ -261,18 +261,28 @@ class Topic < ActiveRecord::Base
|
|||||||
|
|
||||||
# Returns hot topics since a date for display in email digest.
|
# Returns hot topics since a date for display in email digest.
|
||||||
def self.for_digest(user, since)
|
def self.for_digest(user, since)
|
||||||
|
score = "#{ListController.best_period_for(since)}_score"
|
||||||
|
|
||||||
topics = Topic
|
topics = Topic
|
||||||
.visible
|
.visible
|
||||||
.secured(Guardian.new(user))
|
.secured(Guardian.new(user))
|
||||||
.where(closed: false, archived: false)
|
.where(closed: false, archived: false)
|
||||||
.created_since(since)
|
.created_since(since)
|
||||||
.listable_topics
|
.listable_topics
|
||||||
.order(:percent_rank)
|
.joins("LEFT OUTER JOIN top_topics ON top_topics.topic_id = topics.id")
|
||||||
|
.order(TopicQuerySQL.order_top_for(score))
|
||||||
.limit(100)
|
.limit(100)
|
||||||
|
|
||||||
|
# Remove category topics
|
||||||
category_topic_ids = Category.pluck(:topic_id).compact!
|
category_topic_ids = Category.pluck(:topic_id).compact!
|
||||||
if category_topic_ids.present?
|
if category_topic_ids.present?
|
||||||
topics = topics.where("id NOT IN (?)", category_topic_ids)
|
topics = topics.where("topics.id NOT IN (?)", category_topic_ids)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Remove muted categories
|
||||||
|
muted_category_ids = CategoryUser.where(user_id: user.id, notification_level: CategoryUser.notification_levels[:muted]).pluck(:category_id)
|
||||||
|
if muted_category_ids.present?
|
||||||
|
topics = topics.where("topics.category_id NOT IN (?)", muted_category_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
topics
|
topics
|
||||||
|
@ -46,7 +46,7 @@ module TopicQuerySQL
|
|||||||
end
|
end
|
||||||
|
|
||||||
def order_top_for(score)
|
def order_top_for(score)
|
||||||
"top_topics.#{score} DESC, topics.bumped_at DESC"
|
"COALESCE(top_topics.#{score}, 0) DESC, topics.bumped_at DESC"
|
||||||
end
|
end
|
||||||
|
|
||||||
def order_top_with_pinned_category_for(score)
|
def order_top_with_pinned_category_for(score)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user