FEATURE: display the Top tab by default for long-time-no-see users

This commit is contained in:
Régis Hanol 2013-12-30 19:42:45 +01:00
parent a502266c42
commit 54686388fb
2 changed files with 26 additions and 13 deletions

View File

@ -330,6 +330,10 @@ Discourse.User = Discourse.Model.extend({
});
},
hasBeenSeenInTheLastMonth: function() {
return moment().diff(moment(this.get('last_seen_at')), 'month', true) < 1.0;
}.property("last_seen_at"),
/**
Homepage of the user
@ -337,13 +341,16 @@ Discourse.User = Discourse.Model.extend({
@type {String}
**/
homepage: function() {
// top is the default for new users
if (Discourse.SiteSettings.top_menu.indexOf("top") >= 0 &&
this.get("trust_level") === 0) {
return "top";
// 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";
}
}
return Discourse.Utilities.defaultHomepage();
}.property("trust_level")
}.property("trust_level", "hasBeenSeenInTheLastMonth")
});

View File

@ -27,25 +27,31 @@ test("isAllowedToUploadAFile", function() {
});
test("homepage when top is disabled", function() {
var newUser = Discourse.User.create({ trust_level: 0 }),
oldUser = Discourse.User.create({ trust_level: 1 }),
var newUser = Discourse.User.create({ trust_level: 0, last_seen_at: moment() }),
oldUser = Discourse.User.create({ trust_level: 1, last_seen_at: moment() }),
defaultHomepage = Discourse.Utilities.defaultHomepage();
Discourse.SiteSettings.top_menu = "latest";
ok(newUser.get("homepage") === defaultHomepage, "new user's homepage is default when top is disabled");
ok(oldUser.get("homepage") === defaultHomepage, "old user's homepage is default when top is disabled");
equal(newUser.get("homepage"), defaultHomepage, "new user's homepage is default when top is disabled");
equal(oldUser.get("homepage"), defaultHomepage, "old user's homepage is default when top is disabled");
oldUser.set("last_seen_at", moment().subtract('month', 2));
equal(oldUser.get("homepage"), defaultHomepage, "long-time-no-see old user's homepage is default when top is disabled");
});
test("homepage when top is enabled", function() {
var newUser = Discourse.User.create({ trust_level: 0 }),
oldUser = Discourse.User.create({ trust_level: 1 }),
var newUser = Discourse.User.create({ trust_level: 0, last_seen_at: moment() }),
oldUser = Discourse.User.create({ trust_level: 1, last_seen_at: moment() }),
defaultHomepage = Discourse.Utilities.defaultHomepage();
Discourse.SiteSettings.top_menu = "latest|top";
ok(newUser.get("homepage") === "top", "new user's homepage is top when top is enabled");
ok(oldUser.get("homepage") === defaultHomepage, "old user's homepage is default when top is enabled");
equal(newUser.get("homepage"), "top", "new user's homepage is top when top is enabled");
equal(oldUser.get("homepage"), defaultHomepage, "old user's homepage is default when top is enabled");
oldUser.set("last_seen_at", moment().subtract('month', 2));
equal(oldUser.get("homepage"), "top", "long-time-no-see old user's homepage is top when top is enabled");
});