diff --git a/website/common/script/fns/updateStats.js b/website/common/script/fns/updateStats.js index 669fb46fd2f..4cfd8e1f1ee 100644 --- a/website/common/script/fns/updateStats.js +++ b/website/common/script/fns/updateStats.js @@ -111,4 +111,6 @@ module.exports = function updateStats (user, stats, req = {}, analytics) { if (user.addNotification) user.addNotification('REBIRTH_ENABLED'); user.flags.rebirthEnabled = true; } + + if (!req.yesterDailyScored) user.auth.timestamps.updated = new Date(); }; diff --git a/website/common/script/ops/scoreTask.js b/website/common/script/ops/scoreTask.js index 20a8ce20fa6..abe6ccf0fcb 100644 --- a/website/common/script/ops/scoreTask.js +++ b/website/common/script/ops/scoreTask.js @@ -327,6 +327,7 @@ module.exports = function scoreTask (options = {}, req = {}) { } } + req.yesterDailyScored = task.yesterDailyScored; updateStats(user, stats, req); return [delta]; }; diff --git a/website/server/controllers/api-v3/notifications.js b/website/server/controllers/api-v3/notifications.js index e656063529e..4883137f76a 100644 --- a/website/server/controllers/api-v3/notifications.js +++ b/website/server/controllers/api-v3/notifications.js @@ -89,6 +89,7 @@ api.readNotifications = { await user.update({ $pull: { notifications: { id: { $in: notificationsIds } } }, + $set: { 'auth.timestamps.updated': new Date() }, }).exec(); // Update the user version field manually, @@ -185,6 +186,8 @@ api.seeNotifications = { notification.seen = true; } + user.auth.timestamps.updated = new Date(); + await user.save(); res.respond(200, UserNotification.convertNotificationsToSafeJson(user.notifications)); diff --git a/website/server/libs/cron.js b/website/server/libs/cron.js index 09178a35f98..2e01b1a9176 100644 --- a/website/server/libs/cron.js +++ b/website/server/libs/cron.js @@ -289,6 +289,7 @@ export function cron (options = {}) { let todoTally = 0; tasksByType.todos.forEach(task => { // make uncompleted To-Dos redder (further incentive to complete them) + if (task.group.assignedDate && moment(task.group.assignedDate).isAfter(user.auth.timestamps.updated)) return; scoreTask({ task, user, @@ -308,6 +309,7 @@ export function cron (options = {}) { if (!user.party.quest.progress.down) user.party.quest.progress.down = 0; tasksByType.dailys.forEach((task) => { + if (task.group.assignedDate && moment(task.group.assignedDate).isAfter(user.auth.timestamps.updated)) return; let completed = task.completed; // Deduct points for missed Daily tasks let EvadeTask = 0; diff --git a/website/server/libs/taskManager.js b/website/server/libs/taskManager.js index 6cc246f5313..5377be8c4f6 100644 --- a/website/server/libs/taskManager.js +++ b/website/server/libs/taskManager.js @@ -120,6 +120,10 @@ export async function createTasks (req, res, options = {}) { // Push all task ids let taskOrderUpdateQuery = {$push: {}}; + + if (!group && !challenge) { + taskOrderUpdateQuery.$set = {'auth.timestamps.updated': moment().toDate()}; + } for (let taskType in taskOrderToAdd) { taskOrderUpdateQuery.$push[`tasksOrder.${taskType}`] = { $each: taskOrderToAdd[taskType], diff --git a/website/server/models/group.js b/website/server/models/group.js index 568e8530ac8..019e1afa33b 100644 --- a/website/server/models/group.js +++ b/website/server/models/group.js @@ -1431,6 +1431,7 @@ schema.methods.syncTask = async function groupSyncTask (taskToSync, user) { matchingTask.group.id = taskToSync.group.id; matchingTask.userId = user._id; matchingTask.group.taskId = taskToSync._id; + matchingTask.group.assignedDate = moment().toDate(); user.tasksOrder[`${taskToSync.type}s`].unshift(matchingTask._id); } else { _.merge(matchingTask, syncableAttrs(taskToSync)); diff --git a/website/server/models/task.js b/website/server/models/task.js index fe5ec25b4e1..e33c160525b 100644 --- a/website/server/models/task.js +++ b/website/server/models/task.js @@ -104,6 +104,7 @@ export let TaskSchema = new Schema({ id: {$type: String, ref: 'Group', validate: [v => validator.isUUID(v), 'Invalid uuid.']}, broken: {$type: String, enum: ['GROUP_DELETED', 'TASK_DELETED', 'UNSUBSCRIBED']}, assignedUsers: [{$type: String, ref: 'User', validate: [v => validator.isUUID(v), 'Invalid uuid.']}], + assignedDate: {$type: Date}, taskId: {$type: String, ref: 'Task', validate: [v => validator.isUUID(v), 'Invalid uuid.']}, approval: { required: {$type: Boolean, default: false}, diff --git a/website/server/models/user/schema.js b/website/server/models/user/schema.js index 1ae0cb89bd5..868d30c6633 100644 --- a/website/server/models/user/schema.js +++ b/website/server/models/user/schema.js @@ -68,6 +68,7 @@ let schema = new Schema({ timestamps: { created: {$type: Date, default: Date.now}, loggedin: {$type: Date, default: Date.now}, + updated: {$type: Date, default: Date.now}, }, }, // We want to know *every* time an object updates. Mongoose uses __v to designate when an object contains arrays which