diff --git a/src/threadTools.js b/src/threadTools.js index b5dd1fe2bc..8b7355f19c 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -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)); \ No newline at end of file diff --git a/src/topics.js b/src/topics.js index 0282825531..a616df8bb3 100644 --- a/src/topics.js +++ b/src/topics.js @@ -277,29 +277,8 @@ marked.setOptions({ } else callback(teasers); } - - Topics.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')); - }); - } - Topics.getTeaser = function(tid, callback) { - Topics.get_latest_undeleted_pid(tid, function(err, pid) { + threadTools.get_latest_undeleted_pid(tid, function(err, pid) { if (!err) { posts.getPostFields(pid, ['content', 'uid', 'timestamp'], function(postData) {