Fix bug (deletion if lastEdit timestamp is null) + more info in log

This commit is contained in:
Luc Didry 2015-06-27 13:02:10 +02:00
parent 0c969d386f
commit 63e05ddb66

View file

@ -35,46 +35,48 @@ exports.handleMessage = function(hook_name, context, cb) {
if (pad.getHeadRevisionNumber() !== 0) { if (pad.getHeadRevisionNumber() !== 0) {
pad.getLastEdit(function(callback, timestamp) { pad.getLastEdit(function(callback, timestamp) {
var currentTime = (new Date).getTime(); if (timestamp !== undefined && timestamp !== null) {
var currentTime = (new Date).getTime();
// Are we over delay? // Are we over delay?
if ((currentTime - timestamp) > (delay * 1000)) { if ((currentTime - timestamp) > (delay * 1000)) {
// Remove pad // Remove pad
padManager.removePad(padId); padManager.removePad(padId);
console.info('Pad '+padId+' deleted since expired (delay: '+delay+' seconds).'); console.info('Pad '+padId+' deleted since expired (delay: '+delay+' seconds, last edition: '+timestamp+').');
// Create new pad with an explanation // Create new pad with an explanation
padManager.getPad(padId, replaceText, function() { padManager.getPad(padId, replaceText, function() {
if (type === 'COLLABROOM') { if (type === 'COLLABROOM') {
// Create disconnect message // Create disconnect message
var msg = { var msg = {
type: "COLLABROOM", type: "COLLABROOM",
data: { data: {
type: "CUSTOM", type: "CUSTOM",
payload: { payload: {
authorId: message.authorId, authorId: message.authorId,
action: "requestRECONNECT", action: "requestRECONNECT",
padId: padId padId: padId
}
} }
} };
}; // Send disconnect message to all clients
// Send disconnect message to all clients var sessions = padMessageHandler.sessioninfos;
var sessions = padMessageHandler.sessioninfos; Object.keys(sessions).forEach(function(key){
Object.keys(sessions).forEach(function(key){ var session = sessions[key];
var session = sessions[key]; padMessageHandler.handleCustomObjectMessage(msg, false, function(){
padMessageHandler.handleCustomObjectMessage(msg, false, function(){ // TODO: Error handling
// TODO: Error handling }); // Send a message to this session
}); // Send a message to this session });
}); cb(null);
cb(null); } else {
} else { cb();
cb(); }
} });
}); } else {
} else { console.info('Nothing to do with '+padId+' (not expired)');
console.info('Nothing to do with '+padId+' (not expired)'); cb();
cb(); }
} }
}); });
} else { } else {
@ -87,6 +89,6 @@ exports.handleMessage = function(hook_name, context, cb) {
} }
}; };
// Send // Send
function sendToTarget(message, msg){ function sendToTarget(message, msg){
} }