Merge pull request #4487 from cpradio/use-top-default-for-new-users

FEATURE: Use the top period default for users who have been inactive or are new
This commit is contained in:
Régis Hanol
2016-10-13 10:47:18 +02:00
committed by GitHub
3 changed files with 39 additions and 6 deletions

View File

@@ -97,11 +97,10 @@ class SiteSetting < ActiveRecord::Base
].flatten.to_set
end
def self.min_redirected_to_top_period
TopTopic.sorted_periods.each do |p|
period = p[0]
return period if TopTopic.topics_per_period(period) >= SiteSetting.topics_per_period_in_top_page
end
def self.min_redirected_to_top_period(duration)
period = ListController.best_period_for(duration)
return period if TopTopic.topics_per_period(period) >= SiteSetting.topics_per_period_in_top_page
# not enough topics
nil
end

View File

@@ -90,7 +90,7 @@ class UserOption < ActiveRecord::Base
# top must be in the top_menu
return unless SiteSetting.top_menu =~ /(^|\|)top(\||$)/i
# not enough topics
return unless period = SiteSetting.min_redirected_to_top_period
return unless period = SiteSetting.min_redirected_to_top_period(1.days.ago)
if !user.seen_before? || (user.trust_level == 0 && !redirected_to_top_yet?)
update_last_redirected_to_top!