FEATURE: only redirect new users to top page for a limited period

That period is defined by the `redirect_new_users_to_top_page_duration`
site setting and defaults to 7 days.
This commit is contained in:
Régis Hanol
2014-03-05 22:11:01 +01:00
parent b0f3061113
commit ca12ea42a7
4 changed files with 37 additions and 15 deletions

View File

@@ -60,7 +60,7 @@ Discourse.User = Discourse.Model.extend({
return this.get('website').split("/")[2];
}.property('website'),
/**
This user's profile background(in CSS).
@@ -70,10 +70,10 @@ Discourse.User = Discourse.Model.extend({
profileBackground: function() {
var background = this.get('profile_background');
if(Em.isEmpty(background) || !Discourse.SiteSettings.allow_profile_backgrounds) { return; }
return 'background-image: url(' + background + ')';
}.property('profile_background'),
statusIcon: function() {
var desc;
if(this.get('admin')) {
@@ -329,10 +329,10 @@ Discourse.User = Discourse.Model.extend({
data: { use_uploaded_avatar: useUploadedAvatar }
});
},
/*
Clear profile background
@method clearProfileBackground
@returns {Promise} the result of the clear profile background request
*/
@@ -373,10 +373,16 @@ Discourse.User = Discourse.Model.extend({
});
},
hasBeenSeenInTheLastMonth: function() {
return moment().diff(moment(this.get('last_seen_at')), 'month', true) < 1.0;
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
@@ -389,13 +395,13 @@ Discourse.User = Discourse.Model.extend({
// - 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("trust_level") === 0 || !this.get("hasBeenSeenInTheLastMonth")) {
if (this.get("shouldBeRedirectToTopPage") || this.get("hasNotBeenSeenInTheLastMonth")) {
return "top";
}
}
}
return Discourse.Utilities.defaultHomepage();
}.property("trust_level", "hasBeenSeenInTheLastMonth"),
}.property("shouldBeRedirectToTopPage", "hasNotBeenSeenInTheLastMonth"),
updateMutedCategories: function() {
this.set("mutedCategories", Discourse.Category.findByIds(this.muted_category_ids));