BUGFIX: don't show redirect reason if you aren't redirected

Move the redirect to top page logic server-side and make sure the reason
is not shown when top is not in the navigation menu (top_menu).
This commit is contained in:
Régis Hanol
2014-03-07 18:58:53 +01:00
parent c3e5ee1d7e
commit 8214536614
12 changed files with 122 additions and 117 deletions

View File

@@ -19,20 +19,5 @@ Discourse.DiscoveryTopController = Discourse.DiscoveryController.extend({
}
},
redirectedToTopPageReason: function() {
// no need for a reason if the default homepage is 'top'
if (Discourse.Utilities.defaultHomepage() === 'top') { return null; }
// check if the user is authenticated
if (Discourse.User.current()) {
if (Discourse.User.currentProp('trust_level') === 0) {
return I18n.t('filters.top.redirect_reasons.new_user');
} else if (!Discourse.User.currentProp('hasBeenSeenInTheLastMonth')) {
return I18n.t('filters.top.redirect_reasons.not_seen_in_a_month');
}
}
// no reason detected
return null;
}.property(),
hasDisplayedAllTopLists: Em.computed.and('content.yearly', 'content.monthly', 'content.weekly', 'content.daily')
});

View File

@@ -373,16 +373,6 @@ Discourse.User = Discourse.Model.extend({
});
},
hasNotBeenSeenInTheLastMonth: function() {
return moment().diff(moment(this.get("last_seen_at")), "month", true) >= 1.0;
}.property("last_seen_at"),
shouldBeRedirectToTopPage: function() {
if (this.get("trust_level") > 0) { return false; }
var duration = Discourse.SiteSettings.redirect_new_users_to_top_page_duration;
return moment().diff(moment(this.get("created_at")), "days", true) < duration;
}.property("trust_level", "created_at"),
/**
Homepage of the user
@@ -390,18 +380,8 @@ Discourse.User = Discourse.Model.extend({
@type {String}
**/
homepage: function() {
// when there are enough topics, /top is the default for
// - new users
// - long-time-no-see user (ie. > 1 month)
if (Discourse.Site.currentProp("has_enough_topic_to_redirect_to_top_page")) {
if (Discourse.SiteSettings.top_menu.indexOf("top") >= 0) {
if (this.get("shouldBeRedirectToTopPage") || this.get("hasNotBeenSeenInTheLastMonth")) {
return "top";
}
}
}
return Discourse.Utilities.defaultHomepage();
}.property("shouldBeRedirectToTopPage", "hasNotBeenSeenInTheLastMonth"),
return this.get("should_be_redirected_to_top") ? "top" : Discourse.Utilities.defaultHomepage();
}.property("should_be_redirected_to_top"),
updateMutedCategories: function() {
this.set("mutedCategories", Discourse.Category.findByIds(this.muted_category_ids));

View File

@@ -1,7 +1,7 @@
<div class="top-lists">
{{#if redirectedToTopPageReason}}
{{#if currentUser.should_be_redirected_to_top}}
<div class="alert alert-info">
{{redirectedToTopPageReason}}
{{currentUser.redirected_to_top_reason}}
</div>
{{/if}}
{{#if content.yearly}}