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:
Mateus Etto
2017-05-08 10:35:08 -03:00
committed by Keith Holliday
parent 399c91ccab
commit 8c76ccd39b
2 changed files with 63 additions and 7 deletions

View File

@@ -83,11 +83,13 @@ habitrpg.controller('NotificationCtrl',
User.user.groupNotifications.push(notification);
}
var alreadyReadNotification = [];
function handleUserNotifications (after) {
if (!after || after.length === 0) return;
var notificationsToRead = [];
var scoreTaskNotification;
var scoreTaskNotification = [];
User.user.groupNotifications = []; // Flush group notifictions
@@ -150,7 +152,21 @@ habitrpg.controller('NotificationCtrl',
markAsRead = false;
break;
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;
case 'LOGIN_INCENTIVE':
Notification.showLoginIncentive(User.user, notification.data, Social.loadWidgets);
@@ -174,10 +190,25 @@ habitrpg.controller('NotificationCtrl',
if (userReadNotifsPromise) {
userReadNotifsPromise.then(function () {
if (scoreTaskNotification) {
Notification.markdown(scoreTaskNotification.data.message);
User.score({params:{task: scoreTaskNotification.data.scoreTask, direction: "up"}});
User.sync();
// Only run this code for scoring approved tasks
if (scoreTaskNotification.length > 0) {
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);
}
});
}