moved get_last_undeleted_pid to threadTools.js

This commit is contained in:
Julian Lam
2013-07-15 15:08:54 -04:00
parent 31f8be8a0a
commit 87aec422e9
2 changed files with 22 additions and 23 deletions

View File

@@ -3,7 +3,8 @@ var RDB = require('./redis.js'),
categories = require('./categories.js'),
user = require('./user.js'),
async = require('async'),
notifications = require('./notifications.js');
notifications = require('./notifications.js'),
posts = require('./posts');
(function(ThreadTools) {
@@ -266,4 +267,23 @@ var RDB = require('./redis.js'),
});
}
ThreadTools.get_latest_undeleted_pid = function(tid, callback) {
posts.getPostsByTid(tid, 0, -1, function(posts) {
var numPosts = posts.length;
if(!numPosts)
return callback(new Error('no-undeleted-pids-found'));
while(numPosts--) {
if(posts[numPosts].deleted !== '1') {
callback(null, posts[numPosts].pid);
return;
}
}
// If we got here, nothing was found...
callback(new Error('no-undeleted-pids-found'));
});
}
}(exports));