If summary email finds no topics, show topics more than 1 day old from new users

This commit is contained in:
Neil Lalonde 2016-12-19 14:53:53 -05:00
parent 923cf73c6e
commit 74956694e5
4 changed files with 25 additions and 2 deletions

View File

@ -135,7 +135,11 @@ class UserNotifications < ActionMailer::Base
end
# Now fetch some topics and posts to show
topics_for_digest = Topic.for_digest(user, min_date, limit: SiteSetting.digest_topics + SiteSetting.digest_other_topics, top_order: true).to_a
digest_opts = {limit: SiteSetting.digest_topics + SiteSetting.digest_other_topics, top_order: true}
topics_for_digest = Topic.for_digest(user, min_date, digest_opts).to_a
if topics_for_digest.empty? && !user.user_option.try(:include_tl0_in_digests)
topics_for_digest = Topic.for_digest(user, min_date, digest_opts.merge(include_tl0: true)).where('topics.created_at < ?', 24.hours.ago).to_a
end
@popular_topics = topics_for_digest[0,SiteSetting.digest_topics]
@other_new_for_you = topics_for_digest.size > SiteSetting.digest_topics ? topics_for_digest[SiteSetting.digest_topics..-1] : []

View File

@ -338,7 +338,7 @@ class Topic < ActiveRecord::Base
.listable_topics
.includes(:category)
unless user.user_option.try(:include_tl0_in_digests)
unless opts[:include_tl0] || user.user_option.try(:include_tl0_in_digests)
topics = topics.where("COALESCE(users.trust_level, 0) > 0")
end

View File

@ -152,6 +152,18 @@ describe UserNotifications do
end
context "with topics only from new users" do
let!(:new_today) { Fabricate(:topic, user: Fabricate(:user, trust_level: TrustLevel[0], created_at: 10.minutes.ago), title: "Hey everyone look at me") }
let!(:new_yesterday) { Fabricate(:topic, user: Fabricate(:user, trust_level: TrustLevel[0], created_at: 25.hours.ago), created_at: 25.hours.ago, title: "This topic is of interest to you") }
it "returns topics from new users if they're more than 24 hours old" do
expect(subject.to).to eq([user.email])
html = subject.html_part.body.to_s
expect(html).to include(new_yesterday.title)
expect(html).to_not include(new_today.title)
end
end
context "with new topics" do
before do

View File

@ -1354,6 +1354,13 @@ describe Topic do
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank
end
it "returns topics from TL0 users if given include_tl0" do
new_user = Fabricate(:user, trust_level: 0)
topic = Fabricate(:topic, user_id: new_user.id)
expect(Topic.for_digest(user, 1.year.ago, top_order: true, include_tl0: true)).to eq([topic])
end
it "returns topics from TL0 users if enabled in preferences" do
new_user = Fabricate(:user, trust_level: 0)
topic = Fabricate(:topic, user_id: new_user.id)