@ -23,7 +23,7 @@ module.exports = function(Topics) {
} ,
} ,
function ( next ) {
function ( next ) {
Topics . addPostToTopic ( postData . tid , postData . pid , postData . timestamp , 0 , next ) ;
Topics . addPostToTopic ( postData . tid , postData . pid , postData . timestamp , 0 , next ) ;
}
} ,
] , callback ) ;
] , callback ) ;
} ;
} ;
@ -134,43 +134,55 @@ module.exports = function(Topics) {
} ) ;
} ) ;
} ;
} ;
Topics . getLatestUndeletedP ost = function ( tid , callback ) {
Topics . getLatestUndeletedP id = function ( tid , callback ) {
Topics . getLatestUndeleted Pid ( tid , function ( err , pid ) {
Topics . getLatestUndeleted Reply ( tid , function ( err , pid ) {
if ( err ) {
if ( err ) {
return callback ( err ) ;
return callback ( err ) ;
}
}
if ( parseInt ( pid , 10 ) ) {
posts . getPostData ( pid , callback ) ;
return callback ( null , pid . toString ( ) ) ;
}
Topics . getTopicField ( tid , 'mainPid' , function ( err , mainPid ) {
callback ( err , parseInt ( mainPid , 10 ) ? mainPid . toString ( ) : null ) ;
} ) ;
} ) ;
} ) ;
} ;
} ;
Topics . getLatestUndeletedPid = function ( tid , callback ) {
Topics . getLatestUndeletedReply = function ( tid , callback ) {
async . parallel ( {
var isDeleted = false ;
mainPid : function ( next ) {
var done = false ;
Topics . getTopicField ( tid , 'mainPid' , next ) ;
var latestPid = null ;
} ,
var index = 0 ;
pids : function ( next ) {
async . doWhilst (
db . getSortedSetRevRange ( 'tid:' + tid + ':posts' , 0 , - 1 , next ) ;
function ( next ) {
}
db . getSortedSetRevRange ( 'tid:' + tid + ':posts' , index , index , function ( err , pids ) {
} , function ( err , results ) {
if ( err ) {
if ( err ) {
return next ( err ) ;
return callback ( err ) ;
}
}
if ( ! results . mainPid && ( ! Array . isArray ( results . pids ) || ! results . pids . length ) ) {
return callback ( null , null ) ;
}
results . pids . push ( results . mainPid ) ;
if ( ! Array . isArray ( pids ) || ! pids . length ) {
done = true ;
return next ( ) ;
}
async . detectSeries ( results . pids , function ( pid , next ) {
posts . getPostField ( pids [ 0 ] , 'deleted' , function ( err , deleted ) {
posts . getPostField ( pid , 'deleted' , function ( err , deleted ) {
if ( err ) {
next ( parseInt ( deleted , 10 ) === 0 ) ;
return next ( err ) ;
}
latestPid = pids [ 0 ] ;
isDeleted = deleted ;
++ index ;
next ( ) ;
} ) ;
} ) ;
} ) ;
} , function ( pid ) {
} ,
callback ( null , pid ? pid . toString ( ) : null ) ;
function ( ) {
} ) ;
return isDeleted && ! done ;
} ) ;
} ,
function ( err ) {
callback ( err , latestPid ) ;
}
) ;
} ;
} ;
Topics . addPostToTopic = function ( tid , pid , timestamp , votes , callback ) {
Topics . addPostToTopic = function ( tid , pid , timestamp , votes , callback ) {
@ -188,7 +200,12 @@ module.exports = function(Topics) {
function ( next ) {
function ( next ) {
db . sortedSetAdd ( 'tid:' + tid + ':posts:votes' , votes , pid , next ) ;
db . sortedSetAdd ( 'tid:' + tid + ':posts:votes' , votes , pid , next ) ;
}
}
] , callback ) ;
] , function ( err ) {
if ( err ) {
return callback ( err ) ;
}
Topics . updateTeaser ( tid , callback ) ;
} ) ;
}
}
} ) ;
} ) ;
} ;
} ;
@ -202,7 +219,10 @@ module.exports = function(Topics) {
db . sortedSetRemove ( 'tid:' + tid + ':posts:votes' , pid , next ) ;
db . sortedSetRemove ( 'tid:' + tid + ':posts:votes' , pid , next ) ;
}
}
] , function ( err , results ) {
] , function ( err , results ) {
callback ( err ) ;
if ( err ) {
return callback ( err ) ;
}
Topics . updateTeaser ( tid , callback ) ;
} ) ;
} ) ;
} ;
} ;