mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
use getPostsFromSet for recent replies
This commit is contained in:
@@ -13,21 +13,12 @@ var async = require('async'),
|
||||
|
||||
module.exports = function(Categories) {
|
||||
Categories.getRecentReplies = function(cid, uid, count, callback) {
|
||||
if(!parseInt(count, 10)) {
|
||||
if (!parseInt(count, 10)) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
db.getSortedSetRevRange('cid:' + cid + ':pids', 0, count - 1, function(err, pids) {
|
||||
if (err || !Array.isArray(pids) || !pids.length) {
|
||||
return callback(err, []);
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
async.apply(privileges.posts.filter, 'read', pids, uid),
|
||||
function(pids, next) {
|
||||
posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next);
|
||||
}
|
||||
], callback);
|
||||
posts.getPostsFromSet('cid:' + cid + ':pids', uid, 0, count - 1, function(err, data) {
|
||||
callback(err, data ? data.posts : []);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
18
src/posts.js
18
src/posts.js
@@ -8,6 +8,7 @@ var async = require('async'),
|
||||
user = require('./user'),
|
||||
topics = require('./topics'),
|
||||
postTools = require('./postTools'),
|
||||
privileges = require('./privileges'),
|
||||
plugins = require('./plugins');
|
||||
|
||||
(function(Posts) {
|
||||
@@ -85,6 +86,23 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getPostsFromSet = function(set, uid, start, end, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.getSortedSetRevRange(set, start, end, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
privileges.posts.filter('read', pids, uid, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: false}, next);
|
||||
},
|
||||
function(posts, next) {
|
||||
next(null, {posts: posts, nextStart: end + 1});
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.getPostData = function(pid, callback) {
|
||||
db.getObject('post:' + pid, function(err, data) {
|
||||
if(err) {
|
||||
|
||||
@@ -8,8 +8,7 @@ var async = require('async'),
|
||||
meta = require('../meta'),
|
||||
websockets = require('../socket.io'),
|
||||
postTools = require('../postTools'),
|
||||
plugins = require('../plugins'),
|
||||
privileges = require('../privileges');
|
||||
plugins = require('../plugins')
|
||||
|
||||
|
||||
module.exports = function(Posts) {
|
||||
@@ -105,21 +104,4 @@ module.exports = function(Posts) {
|
||||
user.isModerator(uid, cids, callback);
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getPostsFromSet = function(set, uid, start, end, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.getSortedSetRevRange(set, start, end, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
privileges.posts.filter('read', pids, uid, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: false}, next);
|
||||
},
|
||||
function(posts, next) {
|
||||
next(null, {posts: posts, nextStart: end + 1});
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user