Merge branch 'develop' into party-chat-translations
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import mongoose from 'mongoose';
|
||||
import Bluebird from 'bluebird';
|
||||
import validator from 'validator';
|
||||
import baseModel from '../libs/baseModel';
|
||||
import _ from 'lodash';
|
||||
@@ -120,7 +119,7 @@ schema.methods.syncToUser = async function syncChallengeToUser (user) {
|
||||
});
|
||||
}
|
||||
|
||||
let [challengeTasks, userTasks] = await Bluebird.all([
|
||||
let [challengeTasks, userTasks] = await Promise.all([
|
||||
// Find original challenge tasks
|
||||
Tasks.Task.find({
|
||||
userId: {$exists: false},
|
||||
@@ -165,7 +164,7 @@ schema.methods.syncToUser = async function syncChallengeToUser (user) {
|
||||
});
|
||||
|
||||
toSave.push(user.save());
|
||||
return Bluebird.all(toSave);
|
||||
return Promise.all(toSave);
|
||||
};
|
||||
|
||||
async function _fetchMembersIds (challengeId) {
|
||||
@@ -202,7 +201,7 @@ async function _addTaskFn (challenge, tasks, memberId) {
|
||||
|
||||
// Update the user
|
||||
toSave.unshift(User.update({_id: memberId}, updateTasksOrderQ).exec());
|
||||
return await Bluebird.all(toSave);
|
||||
return await Promise.all(toSave);
|
||||
}
|
||||
|
||||
// Add a new task to challenge members
|
||||
@@ -210,11 +209,11 @@ schema.methods.addTasks = async function challengeAddTasks (tasks) {
|
||||
let challenge = this;
|
||||
let membersIds = await _fetchMembersIds(challenge._id);
|
||||
|
||||
let queue = new TaskQueue(Bluebird, 25); // process only 5 users concurrently
|
||||
let queue = new TaskQueue(Promise, 25); // process only 5 users concurrently
|
||||
|
||||
await Bluebird.map(membersIds, queue.wrap((memberId) => {
|
||||
await Promise.all(membersIds.map(queue.wrap((memberId) => {
|
||||
return _addTaskFn(challenge, tasks, memberId);
|
||||
}));
|
||||
})));
|
||||
};
|
||||
|
||||
// Sync updated task to challenge members
|
||||
@@ -267,7 +266,7 @@ schema.methods.unlinkTasks = async function challengeUnlinkTasks (user, keep) {
|
||||
$set: {challenge: {}},
|
||||
}, {multi: true}).exec();
|
||||
|
||||
return Bluebird.all([user.save(), this.save()]);
|
||||
return Promise.all([user.save(), this.save()]);
|
||||
} else { // keep = 'remove-all'
|
||||
let tasks = await Tasks.Task.find(findQuery).select('_id type completed').exec();
|
||||
let taskPromises = tasks.map(task => {
|
||||
@@ -280,7 +279,7 @@ schema.methods.unlinkTasks = async function challengeUnlinkTasks (user, keep) {
|
||||
});
|
||||
user.markModified('tasksOrder');
|
||||
taskPromises.push(user.save(), this.save());
|
||||
return Bluebird.all(taskPromises);
|
||||
return Promise.all(taskPromises);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -358,7 +357,7 @@ schema.methods.closeChal = async function closeChal (broken = {}) {
|
||||
}, {multi: true}).exec(),
|
||||
];
|
||||
|
||||
Bluebird.all(backgroundTasks);
|
||||
Promise.all(backgroundTasks);
|
||||
};
|
||||
|
||||
export let model = mongoose.model('Challenge', schema);
|
||||
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
} from '../libs/errors';
|
||||
import baseModel from '../libs/baseModel';
|
||||
import { sendTxn as sendTxnEmail } from '../libs/email';
|
||||
import Bluebird from 'bluebird';
|
||||
import nconf from 'nconf';
|
||||
import { sendNotification as sendPushNotification } from '../libs/pushNotifications';
|
||||
import pusher from '../libs/pusher';
|
||||
@@ -308,7 +307,7 @@ schema.statics.getGroups = async function getGroups (options = {}) {
|
||||
}
|
||||
});
|
||||
|
||||
let groupsArray = _.reduce(await Bluebird.all(queries), (previousValue, currentValue) => {
|
||||
let groupsArray = _.reduce(await Promise.all(queries), (previousValue, currentValue) => {
|
||||
if (_.isEmpty(currentValue)) return previousValue; // don't add anything to the results if the query returned null or an empty array
|
||||
return previousValue.concat(Array.isArray(currentValue) ? currentValue : [currentValue]); // otherwise concat the new results to the previousValue
|
||||
}, []);
|
||||
@@ -492,7 +491,7 @@ schema.methods.removeGroupInvitations = async function removeGroupInvitations ()
|
||||
return user.save();
|
||||
});
|
||||
|
||||
return Bluebird.all(userUpdates);
|
||||
return Promise.all(userUpdates);
|
||||
};
|
||||
|
||||
// Return true if user is a member of the group
|
||||
@@ -696,13 +695,18 @@ schema.methods.startQuest = async function startQuest (user) {
|
||||
// remove any users from quest.members who aren't in the party
|
||||
let partyId = this._id;
|
||||
let questMembers = this.quest.members;
|
||||
await Bluebird.map(Object.keys(this.quest.members), async (memberId) => {
|
||||
let member = await User.findOne({_id: memberId, 'party._id': partyId}).select('_id').lean().exec();
|
||||
|
||||
if (!member) {
|
||||
delete questMembers[memberId];
|
||||
}
|
||||
});
|
||||
await Promise.all(Object.keys(this.quest.members).map(memberId => {
|
||||
return User.findOne({_id: memberId, 'party._id': partyId})
|
||||
.select('_id')
|
||||
.lean()
|
||||
.exec()
|
||||
.then((member) => {
|
||||
if (!member) {
|
||||
delete questMembers[memberId];
|
||||
}
|
||||
return;
|
||||
});
|
||||
}));
|
||||
|
||||
if (userIsParticipating) {
|
||||
user.party.quest.key = this.quest.key;
|
||||
@@ -942,7 +946,7 @@ schema.methods.finishQuest = async function finishQuest (quest) {
|
||||
}));
|
||||
}
|
||||
|
||||
return Bluebird.all(promises);
|
||||
return Promise.all(promises);
|
||||
};
|
||||
|
||||
function _isOnQuest (user, progress, group) {
|
||||
@@ -1231,7 +1235,7 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all', keepC
|
||||
let challengesToRemoveUserFrom = challenges.map(chal => {
|
||||
return chal.unlinkTasks(user, keep);
|
||||
});
|
||||
await Bluebird.all(challengesToRemoveUserFrom);
|
||||
await Promise.all(challengesToRemoveUserFrom);
|
||||
}
|
||||
|
||||
// Unlink group tasks)
|
||||
@@ -1243,7 +1247,7 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all', keepC
|
||||
let assignedTasksToRemoveUserFrom = assignedTasks.map(task => {
|
||||
return this.unlinkTask(task, user, keep);
|
||||
});
|
||||
await Bluebird.all(assignedTasksToRemoveUserFrom);
|
||||
await Promise.all(assignedTasksToRemoveUserFrom);
|
||||
|
||||
let promises = [];
|
||||
|
||||
@@ -1279,7 +1283,7 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all', keepC
|
||||
|
||||
if (members.length === 0) {
|
||||
promises.push(group.remove());
|
||||
return await Bluebird.all(promises);
|
||||
return await Promise.all(promises);
|
||||
}
|
||||
} else if (group.leader === user._id) { // otherwise If the leader is leaving (or if the leader previously left, and this wasn't accounted for)
|
||||
let query = group.type === 'party' ? {'party._id': group._id} : {guilds: group._id};
|
||||
@@ -1301,7 +1305,7 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all', keepC
|
||||
}
|
||||
promises.push(group.update(update).exec());
|
||||
|
||||
return await Bluebird.all(promises);
|
||||
return await Promise.all(promises);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1435,7 +1439,7 @@ schema.methods.syncTask = async function groupSyncTask (taskToSync, user) {
|
||||
if (matchingTask.tags.indexOf(group._id) === -1) matchingTask.tags.push(group._id); // add tag if missing
|
||||
|
||||
toSave.push(matchingTask.save(), taskToSync.save(), user.save());
|
||||
return Bluebird.all(toSave);
|
||||
return Promise.all(toSave);
|
||||
};
|
||||
|
||||
schema.methods.unlinkTask = async function groupUnlinkTask (unlinkingTask, user, keep) {
|
||||
@@ -1461,7 +1465,7 @@ schema.methods.unlinkTask = async function groupUnlinkTask (unlinkingTask, user,
|
||||
user.markModified('tasksOrder');
|
||||
}
|
||||
|
||||
return Bluebird.all([task.remove(), user.save(), unlinkingTask.save()]);
|
||||
return Promise.all([task.remove(), user.save(), unlinkingTask.save()]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import common from '../../../common';
|
||||
import _ from 'lodash';
|
||||
import moment from 'moment';
|
||||
import Bluebird from 'bluebird';
|
||||
import baseModel from '../../libs/baseModel';
|
||||
import * as Tasks from '../task';
|
||||
import {
|
||||
@@ -58,7 +57,7 @@ function _populateDefaultTasks (user, taskTypes) {
|
||||
// @TODO: default tasks are handled differently now, and not during registration. We should move this code
|
||||
|
||||
let tasksToCreate = [];
|
||||
if (user.registeredThrough === 'habitica-web') return Bluebird.all(tasksToCreate);
|
||||
if (user.registeredThrough === 'habitica-web') return Promise.all(tasksToCreate);
|
||||
|
||||
if (tagsI !== -1) {
|
||||
taskTypes = _.clone(taskTypes);
|
||||
@@ -89,7 +88,7 @@ function _populateDefaultTasks (user, taskTypes) {
|
||||
tasksToCreate.push(...tasksOfType);
|
||||
});
|
||||
|
||||
return Bluebird.all(tasksToCreate)
|
||||
return Promise.all(tasksToCreate)
|
||||
.then((tasksCreated) => {
|
||||
_.each(tasksCreated, (task) => {
|
||||
user.tasksOrder[`${task.type}s`].push(task._id);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import moment from 'moment';
|
||||
import common from '../../../common';
|
||||
|
||||
import Bluebird from 'bluebird';
|
||||
import {
|
||||
chatDefaults,
|
||||
TAVERN_ID,
|
||||
@@ -132,7 +131,7 @@ schema.methods.sendMessage = async function sendMessage (userToReceiveMessage, o
|
||||
sender.markModified('inbox.messages');
|
||||
|
||||
let promises = [userToReceiveMessage.save(), sender.save()];
|
||||
await Bluebird.all(promises);
|
||||
await Promise.all(promises);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user