diff --git a/website/client-old/js/controllers/notificationCtrl.js b/website/client-old/js/controllers/notificationCtrl.js index d379864412..06246bd088 100644 --- a/website/client-old/js/controllers/notificationCtrl.js +++ b/website/client-old/js/controllers/notificationCtrl.js @@ -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); } }); } diff --git a/website/client-old/js/services/userServices.js b/website/client-old/js/services/userServices.js index 826774741b..dd42725b2b 100644 --- a/website/client-old/js/services/userServices.js +++ b/website/client-old/js/services/userServices.js @@ -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);