Update to make note history count in server-side when user logged

This commit is contained in:
Wu Cheng-Han 2016-10-10 20:55:33 +08:00
parent 1d2a9826af
commit 36a1900ce3
3 changed files with 97 additions and 4 deletions

View file

@ -13,6 +13,7 @@ var moment = require('moment');
//core
var config = require("./config.js");
var logger = require("./logger.js");
var history = require("./history.js");
var models = require("./models");
//ot
@ -390,6 +391,12 @@ function finishConnection(socket, note, user) {
note.server.setName(socket, user.name);
note.server.setColor(socket, user.color);
// update user note history
setTimeout(function () {
var noteId = note.alias ? note.alias : LZString.compressToBase64(note.id);
history.updateHistory(user.userid, noteId, note.server.document);
}, 0);
emitOnlineUsers(socket);
emitRefresh(socket);
@ -468,6 +475,7 @@ function startConnection(socket) {
notes[noteId] = {
id: noteId,
alias: note.alias,
owner: owner,
ownerprofile: ownerprofile,
permission: note.permission,
@ -652,6 +660,12 @@ function operationCallback(socket, operation) {
return logger.error('operation callback failed: ' + err);
});
}
// update user note history
setTimeout(function() {
var noteId = note.alias ? note.alias : LZString.compressToBase64(note.id);
history.updateHistory(userId, noteId, note.server.document);
}, 0);
}
// save authorship
note.authorship = models.Note.updateAuthorshipByOperation(operation, userId, note.authorship);