diff --git a/src/app/browser.coffee b/src/app/browser.coffee index 873ce7eb83..1da6586f11 100644 --- a/src/app/browser.coffee +++ b/src/app/browser.coffee @@ -2,12 +2,6 @@ _ = require 'underscore' moment = require 'moment' #algos = require './algos' - -restoreRefs = module.exports.restoreRefs = (model) -> - #refLists - _.each ['habit', 'daily', 'todo', 'reward'], (type) -> - model.refList "_#{type}List", "_user.tasks", "_user.#{type}Ids" - ### Loads JavaScript files from public/js/* If a library is available in a CDN, we put it in (index.html) for better caching. If not, we use diff --git a/src/app/character.coffee b/src/app/character.coffee index 9bf5fd2195..1ac4c446d4 100644 --- a/src/app/character.coffee +++ b/src/app/character.coffee @@ -137,38 +137,6 @@ module.exports.newUserObject = -> when 'reward' then newUser.rewardIds.push guid return newUser -module.exports.updateUser = (model) -> - batch = new BatchUpdate(model) - user = batch.user - obj = batch.obj() - tasks = obj.tasks - - # Remove corrupted tasks - _.each tasks, (task, key) -> - unless task? - user.del("tasks.#{key}") - delete tasks[key] - - batch.startTransaction() - - batch.set('apiToken', derby.uuid()) unless obj.apiToken - - ## Task List Cleanup - # FIXME temporary hack to fix lists (Need to figure out why these are happening) - _.each ['habit','daily','todo','reward'], (type) -> - # 1. remove duplicates - # 2. restore missing zombie tasks back into list - taskIds = _.pluck( _.where(tasks, {type:type}), 'id') - union = _.union obj[type + 'Ids'], taskIds - - # 2. remove empty (grey) tasks - preened = _.filter union, (val) -> _.contains(taskIds, val) and val? - - # There were indeed issues found, set the new list - batch.set("#{type}Ids", preened) # if _.difference(preened, userObj[path]).length != 0 - - batch.commit() - module.exports.BatchUpdate = BatchUpdate = (model) -> user = model.at("_user") transactionInProgress = false diff --git a/src/app/index.coffee b/src/app/index.coffee index 431eb22669..2bf35dd892 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -41,10 +41,20 @@ get '/', (page, model, params, next) -> # return page.redirect 'https://' + req.headers.host + req.url party.partySubscribe page, model, params, next, -> - character.updateUser(model) + user = model.at('_user') + user.setNull('apiToken', derby.uuid()) + + # Remove corrupted tasks + tasks = user.get('tasks') + _.each tasks, (task, key) -> user.del("tasks.#{key}") unless task? + items.server(model) model.set '_view', _view - browser.restoreRefs model + + #refLists + _.each ['habit', 'daily', 'todo', 'reward'], (type) -> + model.refList "_#{type}List", "_user.tasks", "_user.#{type}Ids" + page.render() # ========== CONTROLLER FUNCTIONS ==========