style changes

This commit is contained in:
barisusakli
2016-05-19 16:07:19 +03:00
parent b56baf2530
commit 3f0ca31393
2 changed files with 68 additions and 77 deletions

View File

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

View File

@@ -55,7 +55,7 @@ module.exports = function(Topics) {
} }
Topics.create({uid: results.postData.uid, title: title, cid: cid}, next); Topics.create({uid: results.postData.uid, title: title, cid: cid}, next);
}, },
function( results, next) { function(results, next) {
Topics.updateTopicBookmarks(fromTid, pids, function(){ next( null, results );} ); Topics.updateTopicBookmarks(fromTid, pids, function(){ next( null, results );} );
}, },
function(_tid, next) { function(_tid, next) {