FEATURE: do not redirect to top page when number of topis is low

This commit is contained in:
Régis Hanol
2014-02-17 14:28:12 +01:00
parent 90d20c4373
commit aac4b55926
3 changed files with 34 additions and 7 deletions
@@ -354,16 +354,18 @@ Discourse.User = Discourse.Model.extend({
@type {String}
**/
homepage: function() {
// top is the default for:
// when there are enough topics, /top is the default for
// - new users
// - long-time-no-see user (ie. > 1 month)
if (Discourse.SiteSettings.top_menu.indexOf("top") >= 0) {
if (this.get("trust_level") === 0 || !this.get("hasBeenSeenInTheLastMonth")) {
return "top";
if (Discourse.Site.currentProp("has_enough_topic_to_redirect_to_top_page")) {
if (Discourse.SiteSettings.top_menu.indexOf("top") >= 0) {
if (this.get("trust_level") === 0 || !this.get("hasBeenSeenInTheLastMonth")) {
return "top";
}
}
}
return Discourse.Utilities.defaultHomepage();
}.property("trust_level", "hasBeenSeenInTheLastMonth"),
}.property("trust_level", "hasBeenSeenInTheLastMonth", "Discourse.Site.has_enough_topic_to_redirect_to_top_page"),
updateMutedCategories: function() {
this.set("mutedCategories", Discourse.Category.findByIds(this.muted_category_ids));
+10 -1
View File
@@ -9,7 +9,8 @@ class SiteSerializer < ApplicationSerializer
:top_menu_items,
:anonymous_top_menu_items,
:uncategorized_category_id, # this is hidden so putting it here
:is_readonly
:is_readonly,
:has_enough_topic_to_redirect_to_top_page
has_many :categories, serializer: BasicCategorySerializer, embed: :objects
has_many :post_action_types, embed: :objects
@@ -50,4 +51,12 @@ class SiteSerializer < ApplicationSerializer
Discourse.readonly_mode?
end
def has_enough_topic_to_redirect_to_top_page
Topic.listable_topics
.visible
.includes(:category).references(:category)
.where('COALESCE(categories.topic_id, 0) <> topics.id')
.count > SiteSetting.topics_per_period_in_top_page
end
end