Fixing Duplicate tasks showing up after joining a challenge (#7787)

* fix: prevents double joining challenge by quickly hitting join button on challenge twice. fixes #7730

* Fixing client side parameter updates.
This commit is contained in:
Travis
2016-12-20 17:52:18 -08:00
committed by Keith Holliday
parent 92cbb4a07d
commit 55a8eef3e1
3 changed files with 8 additions and 3 deletions

View File

@@ -79,8 +79,11 @@ schema.methods.syncToUser = async function syncChallengeToUser (user) {
challenge.shortName = challenge.shortName || challenge.name;
// Add challenge to user.challenges
if (!_.contains(user.challenges, challenge._id)) user.challenges.push(challenge._id);
if (!_.contains(user.challenges, challenge._id)) {
// using concat because mongoose's protection against concurrent array modification isn't working as expected.
// see https://github.com/HabitRPG/habitrpg/pull/7787#issuecomment-232972394
user.challenges = user.challenges.concat([challenge._id]);
}
// Sync tags
let userTags = user.tags;
let i = _.findIndex(userTags, {id: challenge._id});