diff --git a/lib/response.js b/lib/response.js index 76793a46..9146c6e3 100644 --- a/lib/response.js +++ b/lib/response.js @@ -14,6 +14,7 @@ var config = require('./config') var logger = require('./logger') var models = require('./models') var utils = require('./utils') +var history = require('./history') // public var response = { @@ -106,6 +107,12 @@ function responseCodiMD (res, note) { }) } +function updateHistory (userId, note, document, time) { + var noteId = note.alias ? note.alias : models.Note.encodeNoteId(note.id) + history.updateHistory(userId, noteId, document, time) + logger.info("history updated") +} + function newNote (req, res, next) { var owner = null var body = '' @@ -125,6 +132,11 @@ function newNote (req, res, next) { alias: req.alias ? req.alias : null, content: body }).then(function (note) { + + if (req.isAuthenticated()) { + updateHistory(owner, note, body); + } + return res.redirect(config.serverURL + '/' + models.Note.encodeNoteId(note.id)) }).catch(function (err) { logger.error(err)