mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
delete completed todos 30/90 days after completion
This commit is contained in:
@@ -2471,12 +2471,25 @@ api.wrap = function(user, main) {
|
|||||||
}
|
}
|
||||||
multiDaysCountAsOneDay = true;
|
multiDaysCountAsOneDay = true;
|
||||||
todoTally = 0;
|
todoTally = 0;
|
||||||
user.todos.forEach(function(task) {
|
|
||||||
|
// Delete completed todos older than 30 days (90 for Subscribers)
|
||||||
|
var completedTodosCutoff = moment(now);
|
||||||
|
if (user.purchased && user.purchased.plan && user.purchased.plan.customerId) {
|
||||||
|
completedTodosCutoff = completedTodosCutoff.subtract(90, 'days');
|
||||||
|
} else {
|
||||||
|
completedTodosCutoff = completedTodosCutoff.subtract(30, 'days');
|
||||||
|
}
|
||||||
|
user.todos = user.todos.filter(function(task) {
|
||||||
var absVal, completed, delta, id;
|
var absVal, completed, delta, id;
|
||||||
if (!task) {
|
if (!task) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = task.id, completed = task.completed;
|
id = task.id, completed = task.completed;
|
||||||
|
if (completed && moment(task.dateCompleted).isBefore(completedTodosCutoff)) {
|
||||||
|
return false; // delete the todo because it's completed and has been kept for 30/90 days
|
||||||
|
}
|
||||||
|
|
||||||
delta = user.ops.score({
|
delta = user.ops.score({
|
||||||
params: {
|
params: {
|
||||||
id: task.id,
|
id: task.id,
|
||||||
@@ -2490,8 +2503,13 @@ api.wrap = function(user, main) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
absVal = completed ? Math.abs(task.value) : task.value;
|
absVal = completed ? Math.abs(task.value) : task.value;
|
||||||
return todoTally += absVal;
|
todoTally += absVal;
|
||||||
|
return true; // keep the todo
|
||||||
});
|
});
|
||||||
|
if (typeof user.markModified === "function") {
|
||||||
|
user.markModified('todos');
|
||||||
|
}
|
||||||
|
|
||||||
dailyChecked = 0;
|
dailyChecked = 0;
|
||||||
dailyDueUnchecked = 0;
|
dailyDueUnchecked = 0;
|
||||||
if ((base = user.party.quest.progress).down == null) {
|
if ((base = user.party.quest.progress).down == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user