mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-17 11:32:16 +00: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 b786c0e71aca4f037412797c6a0c61ce34954c8d. * Fixed gold/xp earn-lose-earnAgain problem * Do not read already read notifications * Removed unnecessary variable
This commit is contained in:
parent
399c91ccab
commit
8c76ccd39b
2 changed files with 63 additions and 7 deletions
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ angular.module('habitrpg')
|
|||
Tasks.createUserTasks(data.body);
|
||||
},
|
||||
|
||||
score: function (data) {
|
||||
score: function (data, callback) {
|
||||
try {
|
||||
$window.habitrpgShared.ops.scoreTask({user: user, task: data.params.task, direction: data.params.direction}, data.params);
|
||||
} catch (err) {
|
||||
|
|
@ -308,9 +308,34 @@ angular.module('habitrpg')
|
|||
|
||||
// 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) {
|
||||
user.ops.sortTask(data);
|
||||
Tasks.moveTask(data.params.id, data.query.to);
|
||||
|
|
|
|||
Loading…
Reference in a new issue