Added document max length limit, enforceMaxLength on change and show modal when reach the limit.

This commit is contained in:
Wu Cheng-Han
2015-07-16 22:46:06 +08:00
parent 57253d28a7
commit d14c5bdc9c
6 changed files with 59 additions and 9 deletions

View File

@@ -95,6 +95,7 @@ EditorSocketIOServer.prototype.onOperation = function (socket, revision, operati
try {
var clientId = socket.id;
var wrappedPrime = this.receiveOperation(revision, wrapped);
if(!wrappedPrime) return;
//console.log("new operation: " + JSON.stringify(wrapped));
this.getClient(clientId).selection = wrappedPrime.meta;
revision = this.operations.length;

View File

@@ -1,3 +1,5 @@
var config = require('../../config');
if (typeof ot === 'undefined') {
var ot = {};
}
@@ -28,7 +30,10 @@ ot.Server = (function (global) {
}
// ... and apply that on the document.
this.document = operation.apply(this.document);
var newDocument = operation.apply(this.document);
// ignore if exceed the max length of document
if(newDocument.length > config.documentmaxlength) return;
this.document = newDocument;
// Store operation in history.
this.operations.push(operation);

View File

@@ -207,6 +207,7 @@ function emitRefresh(socket) {
if (!notename || !notes[notename]) return;
var note = notes[notename];
socket.emit('refresh', {
docmaxlength: config.documentmaxlength,
owner: note.owner,
permission: note.permission,
updatetime: note.updatetime
@@ -218,13 +219,12 @@ var connectionSocketQueue = [];
var isDisconnectBusy = false;
var disconnectSocketQueue = [];
function finishConnection(socket, notename) {
var note = notes[notename];
note.users[socket.id] = users[socket.id];
function finishConnection(socket, note, user) {
note.users[socket.id] = user;
note.socks.push(socket);
note.server.addClient(socket);
note.server.setName(socket, users[socket.id].name);
note.server.setColor(socket, users[socket.id].color);
note.server.setName(socket, user.name);
note.server.setColor(socket, user.color);
emitOnlineUsers(socket);
emitRefresh(socket);
@@ -240,8 +240,9 @@ function finishConnection(socket, notename) {
startConnection(connectionSocketQueue[0]);
if (config.debug) {
var notename = getNotenameFromSocket(socket);
logger.info('SERVER connected a client to [' + notename + ']:');
logger.info(JSON.stringify(users[socket.id]));
logger.info(JSON.stringify(user));
//logger.info(notes);
getStatus(function (data) {
logger.info(JSON.stringify(data));
@@ -293,11 +294,11 @@ function startConnection(socket) {
updatetime: moment(updatetime).valueOf(),
server: server
};
finishConnection(socket, notename);
finishConnection(socket, notes[notename], users[socket.id]);
});
});
} else {
finishConnection(socket, notename);
finishConnection(socket, notes[notename], users[socket.id]);
}
}