Merge branch 'develop' into sabrecat/more-modals

Conflicts:
	common/dist/sprites/spritesmith-largeSprites-0.png
	common/locales/en/front.json
This commit is contained in:
Sabe Jones
2015-11-09 16:24:17 -05:00
182 changed files with 1709 additions and 818 deletions
+2
View File
@@ -123,6 +123,8 @@ api.registerUser = function(req, res, next) {
};
analytics.track('register', analyticsData)
user.registeredThrough = req.headers['x-client']
user.save(function(err, savedUser){
// Clean previous email preferences
// TODO when emails added to EmailUnsubcription they should use lowercase version
+19
View File
@@ -149,6 +149,11 @@ api.get = function(req, res, next) {
// so that users with no party don't get a 404 on every access to the site
return res.json(group);
}
if (!user.contributor.admin) {
_purgeFlagInfoFromChat(group);
}
//Since we have a limit on how many members are populate to the group, we want to make sure the user is always in the group
var userInGroup = _.find(group.members, function(member){ return member._id == user._id; });
//If the group is private or the group is a party, then the user must be a member of the group based on access restrictions above
@@ -247,11 +252,17 @@ api.update = function(req, res, next) {
// TODO remove from api object?
api.attachGroup = function(req, res, next) {
var user = res.locals.user;
var gid = req.params.gid;
var q = (gid == 'party') ? Group.findOne({type: 'party', members: {'$in': [res.locals.user._id]}}) : Group.findById(gid);
q.exec(function(err, group){
if(err) return next(err);
if(!group) return res.json(404, {err: shared.i18n.t('messageGroupNotFound')});
if (!user.contributor.admin) {
_purgeFlagInfoFromChat(group);
}
res.locals.group = group;
next();
});
@@ -271,6 +282,7 @@ api.getChat = function(req, res, next) {
q.exec(function(err, group){
if (err) return next(err);
if (!group && gid!=='party') return res.json(404,{err: shared.i18n.t('messageGroupNotFound')});
res.json(res.locals.group.chat);
gid = null;
});
@@ -1087,3 +1099,10 @@ api.questLeave = function(req, res, next) {
return next(error);
});
}
function _purgeFlagInfoFromChat(group) {
group.chat = _.filter(group.chat, function(message) { return !message.flagCount || message.flagCount < 2; });
_.each(group.chat, function (message) {
message.flags = {};
});
}
-5
View File
@@ -475,11 +475,6 @@ GroupSchema.methods.leave = function(user, keep, mainCb){
GroupSchema.methods.toJSON = function() {
var doc = this.toObject();
if(doc.chat){
doc.chat.forEach(function(msg){
msg.flags = {};
});
}
return doc;
};
+83 -28
View File
@@ -487,34 +487,7 @@ UserSchema.pre('save', function(next) {
// Populate new users with default content
if (this.isNew){
//TODO for some reason this doesn't work here: `_.merge(this, shared.content.userDefaults);`
var self = this;
_.each(['habits', 'dailys', 'todos', 'rewards', 'tags'], function(taskType){
self[taskType] = _.map(shared.content.userDefaults[taskType], function(task){
var newTask = _.cloneDeep(task);
// Render task's text and notes in user's language
if(taskType === 'tags'){
// tasks automatically get id=helpers.uuid() from TaskSchema id.default, but tags are Schema.Types.Mixed - so we need to manually invoke here
newTask.id = shared.uuid();
newTask.name = newTask.name(self.preferences.language);
}else{
newTask.text = newTask.text(self.preferences.language);
if(newTask.notes) {
newTask.notes = newTask.notes(self.preferences.language);
}
if(newTask.checklist){
newTask.checklist = _.map(newTask.checklist, function(checklistItem){
checklistItem.text = checklistItem.text(self.preferences.language);
return checklistItem;
});
}
}
return newTask;
});
});
_populateDefaultsForNewUser(this);
}
//this.markModified('tasks');
@@ -607,6 +580,88 @@ UserSchema.methods.unlink = function(options, cb) {
self.save(cb);
}
function _populateDefaultsForNewUser(user) {
var taskTypes;
if (user.registeredThrough === "habitica-web") {
taskTypes = ['habits', 'dailys', 'todos', 'rewards', 'tags'];
var tutorialCommonSections = [
'habits',
'dailies',
'todos',
'rewards',
'party',
'pets',
'gems',
'skills',
'classes',
'tavern',
'equipment',
'items',
];
_.each(tutorialCommonSections, function(section) {
user.flags.tutorial.common[section] = true;
});
} else {
taskTypes = ['todos', 'tags']
user.flags.showTour = false;
var tourSections = [
'showTour',
'intro',
'classes',
'stats',
'tavern',
'party',
'guilds',
'challenges',
'market',
'pets',
'mounts',
'hall',
'equipment',
];
_.each(tourSections, function(section) {
user.flags.tour[section] = -2;
});
}
_populateDefaultTasks(user, taskTypes);
}
function _populateDefaultTasks (user, taskTypes) {
_.each(taskTypes, function(taskType){
user[taskType] = _.map(shared.content.userDefaults[taskType], function(task){
var newTask = _.cloneDeep(task);
// Render task's text and notes in user's language
if(taskType === 'tags'){
// tasks automatically get id=helpers.uuid() from TaskSchema id.default, but tags are Schema.Types.Mixed - so we need to manually invoke here
newTask.id = shared.uuid();
newTask.name = newTask.name(user.preferences.language);
}else{
newTask.text = newTask.text(user.preferences.language);
if(newTask.notes) {
newTask.notes = newTask.notes(user.preferences.language);
}
if(newTask.checklist){
newTask.checklist = _.map(newTask.checklist, function(checklistItem){
checklistItem.text = checklistItem.text(user.preferences.language);
return checklistItem;
});
}
}
return newTask;
});
});
}
module.exports.schema = UserSchema;
module.exports.model = mongoose.model("User", UserSchema);
// Initially export an empty object so external requires will get
+1 -1
View File
@@ -18,7 +18,7 @@ router.get('/', i18n.getUserLanguage, locals, function(req, res) {
// -------- Static Pages --------
var pages = ['front', 'privacy', 'terms', 'api', 'features', 'videos', 'contact', 'plans', 'new-stuff', 'community-guidelines', 'old-news', 'press-kit', 'faq'];
var pages = ['front', 'privacy', 'terms', 'api', 'features', 'videos', 'contact', 'plans', 'new-stuff', 'community-guidelines', 'old-news', 'press-kit', 'faq', 'overview', 'apps'];
_.each(pages, function(name){
router.get('/static/' + name, i18n.getUserLanguage, locals, function(req, res) {