From 783203b865a4915fa8fc4c10c778ed6d3f1c63c5 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sun, 31 Jul 2011 16:03:53 +0100 Subject: [PATCH] Improved chat message managing --- node/db/Pad.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/node/db/Pad.js b/node/db/Pad.js index 38405bef..43ea1070 100644 --- a/node/db/Pad.js +++ b/node/db/Pad.js @@ -214,7 +214,7 @@ Class('Pad', { db.setSub("pad:"+this.id, ["chatHead"], this.chatHead); }, - getChatMessage: function(entryNum, withName, callback) + getChatMessage: function(entryNum, callback) { var _this = this; var entry; @@ -231,9 +231,9 @@ Class('Pad', { }, //add the authorName function(callback) - { - //skip if we don't need the authorName - if(!withName) + { + //this chat message doesn't exist, return null + if(entry == null) { callback(); return; @@ -287,14 +287,26 @@ Class('Pad', { var entries = []; async.forEach(neededEntries, function(entryObject, callback) { - _this.getChatMessage(entryObject.entryNum, true, function(err, entry) + _this.getChatMessage(entryObject.entryNum, function(err, entry) { entries[entryObject.order] = entry; callback(err); }); }, function(err) { - callback(err, entries); + //sort out broken chat entries + //it looks like in happend in the past that the chat head was + //incremented, but the chat message wasn't added + var cleanedEntries = []; + for(var i=0;i