Merge branch 'develop' into party-chat-translations

This commit is contained in:
Mateus Etto
2018-03-17 00:08:20 +09:00
310 changed files with 10732 additions and 10045 deletions

View File

@@ -16,7 +16,6 @@ import {
NotAuthorized,
} from '../../libs/errors';
import * as Tasks from '../../models/task';
import Bluebird from 'bluebird';
import csvStringify from '../../libs/csvStringify';
import {
createTasks,
@@ -254,7 +253,7 @@ api.joinChallenge = {
addUserJoinChallengeNotification(user);
// Add all challenge's tasks to user's tasks and save the challenge
let results = await Bluebird.all([challenge.syncToUser(user), challenge.save()]);
let results = await Promise.all([challenge.syncToUser(user), challenge.save()]);
let response = results[1].toJSON();
response.group = getChallengeGroupResponse(group);
@@ -306,7 +305,7 @@ api.leaveChallenge = {
if (!challenge.isMember(user)) throw new NotAuthorized(res.t('challengeMemberNotFound'));
// Unlink challenge's tasks from user's tasks and save the challenge
await Bluebird.all([challenge.unlinkTasks(user, keep), challenge.save()]);
await Promise.all([challenge.unlinkTasks(user, keep), challenge.save()]);
res.analytics.track('challenge leave', {
uuid: user._id,
@@ -364,8 +363,8 @@ api.getUserChallenges = {
let resChals = challenges.map(challenge => challenge.toJSON());
// Instead of populate we make a find call manually because of https://github.com/Automattic/mongoose/issues/3833
await Bluebird.all(resChals.map((chal, index) => {
return Bluebird.all([
await Promise.all(resChals.map((chal, index) => {
return Promise.all([
User.findById(chal.leader).select(nameFields).exec(),
Group.findById(chal.group).select(basicGroupFields).exec(),
]).then(populatedData => {
@@ -419,7 +418,7 @@ api.getGroupChallenges = {
let resChals = challenges.map(challenge => challenge.toJSON());
// Instead of populate we make a find call manually because of https://github.com/Automattic/mongoose/issues/3833
await Bluebird.all(resChals.map((chal, index) => {
await Promise.all(resChals.map((chal, index) => {
return User
.findById(chal.leader)
.select(nameFields)
@@ -511,7 +510,7 @@ api.exportChallengeCsv = {
// In v2 this used the aggregation framework to run some computation on MongoDB but then iterated through all
// results on the server so the perf difference isn't that big (hopefully)
let [members, tasks] = await Bluebird.all([
let [members, tasks] = await Promise.all([
User.find({challenges: challengeId})
.select(nameFields)
.sort({_id: 1})

View File

@@ -14,7 +14,6 @@ import pusher from '../../libs/pusher';
import { getAuthorEmailFromMessage } from '../../libs/chat';
import { chatReporterFactory } from '../../libs/chatReporting/chatReporterFactory';
import nconf from 'nconf';
import Bluebird from 'bluebird';
import bannedWords from '../../libs/bannedWords';
import guildsAllowingBannedWords from '../../libs/guildsAllowingBannedWords';
import { getMatchesByWordArray } from '../../libs/stringUtils';
@@ -184,7 +183,7 @@ api.postChat = {
toSave.push(user.save());
}
let [savedGroup] = await Bluebird.all(toSave);
let [savedGroup] = await Promise.all(toSave);
// realtime chat is only enabled for private groups (for now only for parties)
if (savedGroup.privacy === 'private' && savedGroup.type === 'party') {

View File

@@ -1,17 +1,17 @@
import common from '../../../common';
import _ from 'lodash';
import { langCodes } from '../../libs/i18n';
import Bluebird from 'bluebird';
import fsCallback from 'fs';
import path from 'path';
import logger from '../../libs/logger';
import util from 'util';
// Transform fs methods that accept callbacks in ones that return promises
const fs = {
readFile: Bluebird.promisify(fsCallback.readFile, {context: fsCallback}),
writeFile: Bluebird.promisify(fsCallback.writeFile, {context: fsCallback}),
stat: Bluebird.promisify(fsCallback.stat, {context: fsCallback}),
mkdir: Bluebird.promisify(fsCallback.mkdir, {context: fsCallback}),
readFile: util.promisify(fsCallback.readFile).bind(fsCallback),
writeFile: util.promisify(fsCallback.writeFile).bind(fsCallback),
stat: util.promisify(fsCallback.stat).bind(fsCallback),
mkdir: util.promisify(fsCallback.mkdir).bind(fsCallback),
};
let api = {};

View File

@@ -1,5 +1,4 @@
import { authWithHeaders } from '../../middlewares/auth';
import Bluebird from 'bluebird';
import _ from 'lodash';
import nconf from 'nconf';
import {
@@ -137,7 +136,7 @@ api.createGroup = {
user.party._id = group._id;
}
let results = await Bluebird.all([user.save(), group.save()]);
let results = await Promise.all([user.save(), group.save()]);
let savedGroup = results[1];
// Instead of populate we make a find call manually because of https://github.com/Automattic/mongoose/issues/3833
@@ -194,7 +193,7 @@ api.createGroupPlan = {
group.leader = user._id;
user.guilds.push(group._id);
let results = await Bluebird.all([user.save(), group.save()]);
let results = await Promise.all([user.save(), group.save()]);
let savedGroup = results[1];
// Analytics
@@ -617,7 +616,7 @@ api.joinGroup = {
}
}
promises = await Bluebird.all(promises);
promises = await Promise.all(promises);
let response = Group.toJSONCleanChat(promises[0], user);
let leader = await User.findById(response.leader).select(nameFields).exec();
@@ -915,7 +914,7 @@ api.removeGroupMember = {
let message = req.query.message || req.body.message;
_sendMessageToRemoved(group, member, message, isInGroup);
await Bluebird.all([
await Promise.all([
member.save(),
group.save(),
]);
@@ -1167,7 +1166,7 @@ api.inviteToGroup = {
if (uuids) {
let uuidInvites = uuids.map((uuid) => _inviteByUUID(uuid, group, user, req, res));
let uuidResults = await Bluebird.all(uuidInvites);
let uuidResults = await Promise.all(uuidInvites);
results.push(...uuidResults);
}
@@ -1175,7 +1174,7 @@ api.inviteToGroup = {
let emailInvites = emails.map((invite) => _inviteByEmail(invite, group, user, req, res));
user.invitesSent += emails.length;
await user.save();
let emailResults = await Bluebird.all(emailInvites);
let emailResults = await Promise.all(emailInvites);
results.push(...emailResults);
}

View File

@@ -18,7 +18,6 @@ import {
getUserInfo,
sendTxn as sendTxnEmail,
} from '../../libs/email';
import Bluebird from 'bluebird';
import { sendNotification as sendPushNotification } from '../../libs/pushNotifications';
import { achievements } from '../../../../website/common/';
@@ -552,7 +551,7 @@ api.transferGems = {
receiver.balance += amount;
sender.balance -= amount;
let promises = [receiver.save(), sender.save()];
await Bluebird.all(promises);
await Promise.all(promises);
// generate the message in both languages, so both users can understand it
let receiverLang = receiver.preferences.language;

View File

@@ -3,7 +3,7 @@ import { authWithHeaders } from '../../middlewares/auth';
let api = {};
// @TODO export this const, cannot export it from here because only routes are exported from controllers
const LAST_ANNOUNCEMENT_TITLE = 'DYSHEARTENER DEFEATED!';
const LAST_ANNOUNCEMENT_TITLE = 'KEYS TO THE KENNELS AND USE CASE SPOTLIGHT';
const worldDmg = { // @TODO
bailey: false,
};
@@ -31,18 +31,27 @@ api.getNews = {
<div class="media-body">
<h1 class="align-self-center">${res.t('newStuff')}</h1>
</div>
<div class="promo_hippogriff"></div>
</div>
<h2>3/8/2018 - ${LAST_ANNOUNCEMENT_TITLE}</h2>
<h2>3/15/2018 - ${LAST_ANNOUNCEMENT_TITLE}</h2>
<hr/>
<h3>World Boss: Dysheartener Defeated!</h3>
<p>Together, everyone in Habitica strikes a final blow to their tasks, and the Dysheartener rears back, shrieking with dismay. "What's wrong, Dysheartener?" AnnDeLune calls, eyes sparkling. "Feeling discouraged?"</p>
<p>Glowing pink fractures crack across the Dysheartener's carapace, and it shatters in a puff of pink smoke. As a renewed sense of vigor and determination sweeps across the land, a flurry of delightful sweets rains down upon everyone.</p>
<p>The crowd cheers wildly, hugging each other as their pets happily chew on the belated Valentine's treats. Suddenly, a joyful chorus of song cascades through the air, and gleaming silhouettes soar across the sky.</p>
<p>Our newly-invigorated optimism has attracted a flock of Hopeful Hippogriffs! The graceful creatures alight upon the ground, ruffling their feathers with interest and prancing about. "It looks like we've made some new friends to help keep our spirits high, even when our tasks are daunting," Lemoness says.</p>
<p>Beffymaroo already has her arms full with feathered fluffballs. "Maybe they'll help us rebuild the damaged areas of Habitica!"</p>
<p>Crooning and singing, the Hippogriffs lead the way as all the Habitcans work together to restore our beloved home.</p>
<div class="small mb-3">by Lemoness, Beffymaroo, SabreCat, AnnDeLune, viirus, piyorii, and Apollo</div>
<div class="media align-items-center">
<div class="media-body">
<h3>Release Pets & Mounts!</h3>
<p>The Keys to the Kennels have returned! Now, when you collect all 90 standard pets or mounts, you can release them for 4 Gems, letting you collect them all over again! If you want a real challenge, you can attain the elusive Triad Bingo by filling your stable with all of both, then set them all free at once for 6 Gems!</p>
</div>
<div class="pet_key ml-3"></div>
</div>
<p>Scroll to the bottom of <a href='/shops/market' target='_blank'>the Market</a> to purchase a Key. It takes effect immediately on purchase, so say your goodbyes first!</p>
<div class="small mb-3">by TheHollidayInn, Apollo, Lemoness, deilann, and Megan</div>
<div class="media align-items-center">
<div class="scene_sweeping mr-3"></div>
<div class="media-body">
<h3>Use Case Spotlight: Spring Cleaning</h3>
<p>This month's <a href='https://habitica.wordpress.com/2018/03/15/use-case-spotlight-spring-cleaning/' target='_blank'>Use Case Spotlight</a> is about Spring Cleaning! It features a number of great suggestions submitted by Habiticans in the <a href='/groups/guild/1d3a10bf-60aa-4806-a38b-82d1084a59e6' target='_blank'>Use Case Spotlights Guild</a>. We hope it helps any of you who might be looking to start spring with a nice, clean dwelling.</p>
<p>Plus, we're collecting user submissions for the next spotlight! How do you use Habitica to Make a Difference? Well be featuring player-submitted examples in Use Case Spotlights on the Habitica Blog next month, so post your suggestions in the Use Case Spotlight Guild now. We look forward to learning more about how you use Habitica to improve your life and get things done!</p>
<div class="small mb-3">by Beffymaroo</div>
</div>
</div>
</div>
`,
});

View File

@@ -1,5 +1,4 @@
import _ from 'lodash';
import Bluebird from 'bluebird';
import { authWithHeaders } from '../../middlewares/auth';
import analytics from '../../libs/analyticsService';
import {
@@ -109,7 +108,7 @@ api.inviteToQuest = {
await group.startQuest(user);
}
let [savedGroup] = await Bluebird.all([
let [savedGroup] = await Promise.all([
group.save(),
user.save(),
]);
@@ -312,7 +311,7 @@ api.forceStart = {
await group.startQuest(user);
let [savedGroup] = await Bluebird.all([
let [savedGroup] = await Promise.all([
group.save(),
user.save(),
]);
@@ -372,7 +371,7 @@ api.cancelQuest = {
group.quest = Group.cleanGroupQuest();
group.markModified('quest');
let [savedGroup] = await Bluebird.all([
let [savedGroup] = await Promise.all([
group.save(),
User.update(
{'party._id': groupId},
@@ -445,7 +444,7 @@ api.abortQuest = {
group.quest = Group.cleanGroupQuest();
group.markModified('quest');
let [groupSaved] = await Bluebird.all([group.save(), memberUpdates, questLeaderUpdate]);
let [groupSaved] = await Promise.all([group.save(), memberUpdates, questLeaderUpdate]);
res.respond(200, groupSaved.quest);
},
@@ -490,7 +489,7 @@ api.leaveQuest = {
user.party.quest = Group.cleanQuestProgress();
user.markModified('party.quest');
let [savedGroup] = await Bluebird.all([
let [savedGroup] = await Promise.all([
group.save(),
user.save(),
]);

View File

@@ -20,7 +20,6 @@ import {
setNextDue,
} from '../../libs/taskManager';
import common from '../../../common';
import Bluebird from 'bluebird';
import _ from 'lodash';
import logger from '../../libs/logger';
import moment from 'moment';
@@ -598,7 +597,7 @@ api.scoreTask = {
});
managerPromises.push(task.save());
await Bluebird.all(managerPromises);
await Promise.all(managerPromises);
throw new NotAuthorized(res.t('taskApprovalHasBeenRequested'));
}
@@ -647,7 +646,7 @@ api.scoreTask = {
task.save(),
];
if (taskOrderPromise) promises.push(taskOrderPromise);
let results = await Bluebird.all(promises);
let results = await Promise.all(promises);
let savedUser = results[0];
@@ -1132,7 +1131,7 @@ api.unlinkAllTasks = {
if (!validTasks) throw new BadRequest(res.t('cantOnlyUnlinkChalTask'));
if (keep === 'keep-all') {
await Bluebird.all(tasks.map(task => {
await Promise.all(tasks.map(task => {
task.challenge = {};
return task.save();
}));
@@ -1149,7 +1148,7 @@ api.unlinkAllTasks = {
toSave.push(user.save());
await Bluebird.all(toSave);
await Promise.all(toSave);
}
res.respond(200, {});
@@ -1199,7 +1198,7 @@ api.unlinkOneTask = {
} else { // remove
if (task.type !== 'todo' || !task.completed) { // eslint-disable-line no-lonely-if
removeFromArray(user.tasksOrder[`${task.type}s`], taskId);
await Bluebird.all([user.save(), task.remove()]);
await Promise.all([user.save(), task.remove()]);
} else {
await task.remove();
}
@@ -1317,7 +1316,7 @@ api.deleteTask = {
// See https://github.com/HabitRPG/habitica/pull/9321#issuecomment-354187666 for more info
if (!challenge) user._v++;
await Bluebird.all([taskOrderUpdate, task.remove()]);
await Promise.all([taskOrderUpdate, task.remove()]);
} else {
await task.remove();
}

View File

@@ -1,5 +1,4 @@
import { authWithHeaders } from '../../../middlewares/auth';
import Bluebird from 'bluebird';
import * as Tasks from '../../../models/task';
import { model as Group } from '../../../models/group';
import { model as User } from '../../../models/user';
@@ -209,7 +208,7 @@ api.assignTask = {
let promises = [];
promises.push(group.syncTask(task, assignedUser));
promises.push(group.save());
await Bluebird.all(promises);
await Promise.all(promises);
res.respond(200, task);
},
@@ -354,7 +353,7 @@ api.approveTask = {
managerPromises.push(task.save());
managerPromises.push(assignedUser.save());
await Bluebird.all(managerPromises);
await Promise.all(managerPromises);
res.respond(200, task);
},

View File

@@ -9,7 +9,6 @@ import {
model as Group,
} from '../../models/group';
import * as Tasks from '../../models/task';
import Bluebird from 'bluebird';
import _ from 'lodash';
import * as passwordUtils from '../../libs/password';
import {
@@ -415,7 +414,7 @@ api.deleteUser = {
return group.leave(user, 'remove-all');
});
await Bluebird.all(groupLeavePromises);
await Promise.all(groupLeavePromises);
await Tasks.Task.remove({
userId: user._id,
@@ -1470,7 +1469,7 @@ api.userRebirth = {
toSave.push(user.save());
await Bluebird.all(toSave);
await Promise.all(toSave);
res.respond(200, ...rebirthRes);
},
@@ -1627,7 +1626,7 @@ api.userReroll = {
let promises = tasks.map(task => task.save());
promises.push(user.save());
await Bluebird.all(promises);
await Promise.all(promises);
res.respond(200, ...rerollRes);
},
@@ -1668,7 +1667,7 @@ api.userReset = {
let resetRes = common.ops.reset(user, tasks);
await Bluebird.all([
await Promise.all([
Tasks.Task.remove({_id: {$in: resetRes[0].tasksToRemove}, userId: user._id}),
user.save(),
]);