style changes

v1.18.x
barisusakli 9 years ago
parent b56baf2530
commit 3f0ca31393

@ -341,7 +341,7 @@ var social = require('./social');
Topics.updateTopicBookmarks = function(tid, pids, callback) { Topics.updateTopicBookmarks = function(tid, pids, callback) {
var maxIndex; var maxIndex;
var Posts = posts;
async.waterfall([ async.waterfall([
function(next) { function(next) {
Topics.getPostCount(tid, next); Topics.getPostCount(tid, next);
@ -351,72 +351,63 @@ var social = require('./social');
Topics.getTopicBookmarks(tid, next); Topics.getTopicBookmarks(tid, next);
}, },
function(bookmarks, next) { function(bookmarks, next) {
var uids = bookmarks.map( function( bookmark ){return bookmark.value}); var forkedPosts = pids.map(function(pid) {
var forkedPosts = pids.map( function( pid ){ return { pid: pid, tid: tid }; } ); return {pid: pid, tid: tid};
var uidBookmark = new Object(); });
var uidData = bookmarks.map(
function( bookmark ){ var uidData = bookmarks.map(function(bookmark) {
var u = new Object(); return {
u.uid = bookmark.value; uid: bookmark.value,
u.bookmark = bookmark.score; bookmark: bookmark.score
return u; };
}); });
async.map(
uidData, async.map(uidData, function(data, mapCallback) {
function( data, mapCallback ){ posts.getPostIndices(forkedPosts, data.uid, function(err, indices) {
Posts.getPostIndices(
forkedPosts,
data.uid,
function( err, indices ){
if (err) { if (err) {
callback( err ); return callback(err);
} }
data.postIndices = indices; data.postIndices = indices;
mapCallback(null, data); mapCallback(null, data);
} ) });
}, }, function(err, results) {
function( err, results ){
if (err) { if (err) {
return callback(); return callback(err);
} }
async.map( async.map(results, function(data, mapCallback) {
results,
function( data, mapCallback ){
var uid = data.uid; var uid = data.uid;
var bookmark = data.bookmark; var bookmark = data.bookmark;
bookmark = bookmark < maxIndex ? bookmark : maxIndex; bookmark = bookmark < maxIndex ? bookmark : maxIndex;
var postIndices = data.postIndices; var postIndices = data.postIndices;
var i;
for( i = 0; i < postIndices.length && postIndices[i] < data.bookmark; ++i ){ for (var i = 0; i < postIndices.length && postIndices[i] < data.bookmark; ++i ){
--bookmark; --bookmark;
} }
if( bookmark != data.bookmark ){ if (parseInt(bookmark, 10) !== parseInt(data.bookmark, 10)) {
mapCallback( null, { uid: uid, bookmark: bookmark } ); mapCallback( null, { uid: uid, bookmark: bookmark } );
} } else {
else{
mapCallback( null, null ); mapCallback( null, null );
} }
}, }, function(err, results) {
function( err, results ){ if (err) {
async.map( results, return callback(err);
function(ui, cb ){ }
async.map(results, function(ui, cb) {
if( ui && ui.bookmark) { if( ui && ui.bookmark) {
Topics.setUserBookmark(tid, ui.uid, ui.bookmark, cb); Topics.setUserBookmark(tid, ui.uid, ui.bookmark, cb);
} } else {
else{
return cb(null, null); return cb(null, null);
} }
}, }, function(err) {
function( err, results ){ next(err);
next(); });
} });
); });
}
);
} }
); ], function(err){
}], callback(err);
function( err, result ){ callback();} ); });
}; };
}(exports)); }(exports));

Loading…
Cancel
Save