Skip to content

Commit

Permalink
feat(groups): don't penalize for tasks assigned since last activity
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreCat committed Aug 6, 2019
1 parent c398bfa commit 7de77c8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions website/common/script/fns/updateStats.js
Expand Up @@ -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();
};
1 change: 1 addition & 0 deletions website/common/script/ops/scoreTask.js
Expand Up @@ -327,6 +327,7 @@ module.exports = function scoreTask (options = {}, req = {}) {
}
}

req.yesterDailyScored = task.yesterDailyScored;
updateStats(user, stats, req);
return [delta];
};
3 changes: 3 additions & 0 deletions website/server/controllers/api-v3/notifications.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions website/server/libs/cron.js
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions website/server/libs/taskManager.js
Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions website/server/models/group.js
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions website/server/models/task.js
Expand Up @@ -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},
Expand Down
1 change: 1 addition & 0 deletions website/server/models/user/schema.js
Expand Up @@ -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
Expand Down

0 comments on commit 7de77c8

Please sign in to comment.