From 193e89a79e402c33d978a5f1b4dcc2502676ec83 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Sun, 10 Jan 2016 15:57:22 +0100 Subject: [PATCH] fix index when marking task as modified after history preening --- common/script/preenUserHistory.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/common/script/preenUserHistory.js b/common/script/preenUserHistory.js index 507b24c88b..97280f3252 100644 --- a/common/script/preenUserHistory.js +++ b/common/script/preenUserHistory.js @@ -61,12 +61,15 @@ export function preenUserHistory (user) { let isSubscribed = user.purchased && user.purchased.plan && user.purchased.plan.customerId; let minHistoryLength = isSubscribed ? 365 : 60; - _.each(user.habits.concat(user.dailys), (task, index) => { + function _processTask (task, index) { 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`); } - }); + } + + _.each(user.habits, _processTask); + _.each(user.dailys, _processTask); _.defaults(user.history, { todos: [], @@ -74,12 +77,12 @@ export function preenUserHistory (user) { }); 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'); } 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'); } }