mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Fix bugs with approved tasks in a Group Plan (#8629)
* Store all approved tasks in an array
* Created bulkScore using score callback
* Removed unnecessary code
* Added verification to run the code only for Approved Tasks
* Created scoreTasks on server and necessary code on client
* Revert "Created scoreTasks on server and necessary code on client"
This reverts commit b786c0e71a.
* Fixed gold/xp earn-lose-earnAgain problem
* Do not read already read notifications
* Removed unnecessary variable
This commit is contained in:
committed by
Keith Holliday
parent
399c91ccab
commit
8c76ccd39b
@@ -83,11 +83,13 @@ habitrpg.controller('NotificationCtrl',
|
|||||||
User.user.groupNotifications.push(notification);
|
User.user.groupNotifications.push(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var alreadyReadNotification = [];
|
||||||
|
|
||||||
function handleUserNotifications (after) {
|
function handleUserNotifications (after) {
|
||||||
if (!after || after.length === 0) return;
|
if (!after || after.length === 0) return;
|
||||||
|
|
||||||
var notificationsToRead = [];
|
var notificationsToRead = [];
|
||||||
var scoreTaskNotification;
|
var scoreTaskNotification = [];
|
||||||
|
|
||||||
User.user.groupNotifications = []; // Flush group notifictions
|
User.user.groupNotifications = []; // Flush group notifictions
|
||||||
|
|
||||||
@@ -150,7 +152,21 @@ habitrpg.controller('NotificationCtrl',
|
|||||||
markAsRead = false;
|
markAsRead = false;
|
||||||
break;
|
break;
|
||||||
case 'SCORED_TASK':
|
case 'SCORED_TASK':
|
||||||
scoreTaskNotification = notification;
|
// Search if it is a read notification
|
||||||
|
for (var i = 0; i < alreadyReadNotification.length; i++) {
|
||||||
|
if (alreadyReadNotification[i] == notification.id) {
|
||||||
|
markAsRead = false; // Do not let it be read again
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only process the notification if it is an unread notification
|
||||||
|
if (markAsRead) {
|
||||||
|
scoreTaskNotification.push(notification);
|
||||||
|
|
||||||
|
// Add to array of read notifications
|
||||||
|
alreadyReadNotification.push(notification.id);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'LOGIN_INCENTIVE':
|
case 'LOGIN_INCENTIVE':
|
||||||
Notification.showLoginIncentive(User.user, notification.data, Social.loadWidgets);
|
Notification.showLoginIncentive(User.user, notification.data, Social.loadWidgets);
|
||||||
@@ -174,10 +190,25 @@ habitrpg.controller('NotificationCtrl',
|
|||||||
|
|
||||||
if (userReadNotifsPromise) {
|
if (userReadNotifsPromise) {
|
||||||
userReadNotifsPromise.then(function () {
|
userReadNotifsPromise.then(function () {
|
||||||
if (scoreTaskNotification) {
|
|
||||||
Notification.markdown(scoreTaskNotification.data.message);
|
// Only run this code for scoring approved tasks
|
||||||
User.score({params:{task: scoreTaskNotification.data.scoreTask, direction: "up"}});
|
if (scoreTaskNotification.length > 0) {
|
||||||
User.sync();
|
var approvedTasks = [];
|
||||||
|
for (var i = 0; i < scoreTaskNotification.length; i++) {
|
||||||
|
// Array with all approved tasks
|
||||||
|
approvedTasks.push({
|
||||||
|
params: {
|
||||||
|
task: scoreTaskNotification[i].data.scoreTask,
|
||||||
|
direction: "up"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Show notification of task approved
|
||||||
|
Notification.markdown(scoreTaskNotification[i].data.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Score approved tasks
|
||||||
|
User.bulkScore(approvedTasks);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ angular.module('habitrpg')
|
|||||||
Tasks.createUserTasks(data.body);
|
Tasks.createUserTasks(data.body);
|
||||||
},
|
},
|
||||||
|
|
||||||
score: function (data) {
|
score: function (data, callback) {
|
||||||
try {
|
try {
|
||||||
$window.habitrpgShared.ops.scoreTask({user: user, task: data.params.task, direction: data.params.direction}, data.params);
|
$window.habitrpgShared.ops.scoreTask({user: user, task: data.params.task, direction: data.params.direction}, data.params);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -308,9 +308,34 @@ angular.module('habitrpg')
|
|||||||
|
|
||||||
// Analytics.track({'hitType':'event','eventCategory':'behavior','eventAction':'acquire item','itemName':after.key,'acquireMethod':'Drop'});
|
// Analytics.track({'hitType':'event','eventCategory':'behavior','eventAction':'acquire item','itemName':after.key,'acquireMethod':'Drop'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
bulkScore: function (data) {
|
||||||
|
var scoreCallback = function () {
|
||||||
|
setTimeout(function() {
|
||||||
|
if (data.length > 0) {
|
||||||
|
// Remove the first task from array and call the score function
|
||||||
|
userServices.score(data.shift(), scoreCallback);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Only run when finished scoring
|
||||||
|
sync();
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
|
}
|
||||||
|
|
||||||
|
// First call to score
|
||||||
|
if (data.length > 0) {
|
||||||
|
userServices.score(data.shift(), scoreCallback);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
sortTask: function (data) {
|
sortTask: function (data) {
|
||||||
user.ops.sortTask(data);
|
user.ops.sortTask(data);
|
||||||
Tasks.moveTask(data.params.id, data.query.to);
|
Tasks.moveTask(data.params.id, data.query.to);
|
||||||
|
|||||||
Reference in New Issue
Block a user