Skip to content

Node.js based forum software built for the modern web

closes #1998

barisusaklib858b120da30
diff --git a/src/posts.js b/src/posts.js
index 4f33a78f47..ab87cbeb2a 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -102,7 +102,7 @@ var async = require('async'),
return callback(null, []);
}
- Posts.getPostsByPids(pids, tid, callback);
+ Posts.getPostsByPids(pids, callback);
});
};
@@ -110,7 +110,7 @@ var async = require('async'),
db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, end, callback);
};
- Posts.getPostsByPids = function(pids, tid, callback) {
+ Posts.getPostsByPids = function(pids, callback) {
var keys = [];
for(var x=0, numPids=pids.length; x<numPids; ++x) {
@@ -144,7 +144,7 @@ var async = require('async'),
return callback(err);
}
- plugins.fireHook('filter:post.getPosts', {tid: tid, posts: posts}, function(err, data) {
+ plugins.fireHook('filter:post.getPosts', {posts: posts}, function(err, data) {
if (err) {
return callback(err);
}
diff --git a/src/topics.js b/src/topics.js
index 5eeeab2a3c..a2d3130ae3 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -266,7 +266,7 @@ var async = require('async'),
if (!pids.length) {
return next(null, []);
}
- posts.getPostsByPids(pids, tid, function(err, posts) {
+ posts.getPostsByPids(pids, function(err, posts) {
if (err) {
return next(err);
}
@@ -315,7 +315,7 @@ var async = require('async'),
if (!parseInt(mainPid, 10)) {
return callback(null, []);
}
- posts.getPostsByPids([mainPid], tid, function(err, postData) {
+ posts.getPostsByPids([mainPid], function(err, postData) {
if (err) {
return callback(err);
}
@@ -328,6 +328,34 @@ var async = require('async'),
});
};
+ Topics.getMainPosts = function(tids, uid, callback) {
+ var keys = tids.map(function(tid) {
+ return 'topic:' + tid;
+ });
+
+ db.getObjectsFields(keys, ['mainPid'], function(err, topicData) {
+ if (err) {
+ return callback(err);
+ }
+
+ var mainPids = topicData.map(function(topic) {
+ return topic ? topic.mainPid : null;
+ });
+
+ posts.getPostsByPids(mainPids, function(err, postData) {
+ if (err) {
+ return callback(err);
+ }
+
+ if (!Array.isArray(postData) || !postData.length) {
+ return callback(null, []);
+ }
+
+ Topics.addPostData(postData, uid, callback);
+ });
+ });
+ }
+
Topics.getTeasers = function(tids, uid, callback) {
if(!Array.isArray(tids)) {
return callback(null, []);