fix index when marking task as modified after history preening

This commit is contained in:
Matteo Pagliazzi
2016-01-10 15:57:22 +01:00
parent c5ad006007
commit 193e89a79e

View File

@@ -61,12 +61,15 @@ export function preenUserHistory (user) {
let isSubscribed = user.purchased && user.purchased.plan && user.purchased.plan.customerId; let isSubscribed = user.purchased && user.purchased.plan && user.purchased.plan.customerId;
let minHistoryLength = isSubscribed ? 365 : 60; let minHistoryLength = isSubscribed ? 365 : 60;
_.each(user.habits.concat(user.dailys), (task, index) => { function _processTask (task, index) {
if (task.history && task.history.length > minHistoryLength) { if (task.history && task.history.length > minHistoryLength) {
task.history = preenHistory(task.history, isSubscribed); task.history = preenHistory(task.history, isSubscribed, user.preferences.timezoneOffset);
if (user.markModified) user.markModified(`${task.type}s.${index}.history`); if (user.markModified) user.markModified(`${task.type}s.${index}.history`);
} }
}); }
_.each(user.habits, _processTask);
_.each(user.dailys, _processTask);
_.defaults(user.history, { _.defaults(user.history, {
todos: [], todos: [],
@@ -74,12 +77,12 @@ export function preenUserHistory (user) {
}); });
if (user.history.exp.length > minHistoryLength) { if (user.history.exp.length > minHistoryLength) {
user.history.exp = preenHistory(user.history.exp, isSubscribed); user.history.exp = preenHistory(user.history.exp, isSubscribed, user.preferences.timezoneOffset);
user.markModified('history.exp'); user.markModified('history.exp');
} }
if (user.history.todos.length > minHistoryLength) { if (user.history.todos.length > minHistoryLength) {
user.history.todos = preenHistory(user.history.todos, isSubscribed); user.history.todos = preenHistory(user.history.todos, isSubscribed, user.preferences.timezoneOffset);
user.markModified('history.todos'); user.markModified('history.todos');
} }
} }