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) {
|
module.exports = function(Categories) {
|
||||||
Categories.getRecentReplies = function(cid, uid, count, callback) {
|
Categories.getRecentReplies = function(cid, uid, count, callback) {
|
||||||
if(!parseInt(count, 10)) {
|
if (!parseInt(count, 10)) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
db.getSortedSetRevRange('cid:' + cid + ':pids', 0, count - 1, function(err, pids) {
|
posts.getPostsFromSet('cid:' + cid + ':pids', uid, 0, count - 1, function(err, data) {
|
||||||
if (err || !Array.isArray(pids) || !pids.length) {
|
callback(err, data ? data.posts : []);
|
||||||
return callback(err, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.waterfall([
|
|
||||||
async.apply(privileges.posts.filter, 'read', pids, uid),
|
|
||||||
function(pids, next) {
|
|
||||||
posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next);
|
|
||||||
}
|
|
||||||
], callback);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
18
src/posts.js
18
src/posts.js
@@ -8,6 +8,7 @@ var async = require('async'),
|
|||||||
user = require('./user'),
|
user = require('./user'),
|
||||||
topics = require('./topics'),
|
topics = require('./topics'),
|
||||||
postTools = require('./postTools'),
|
postTools = require('./postTools'),
|
||||||
|
privileges = require('./privileges'),
|
||||||
plugins = require('./plugins');
|
plugins = require('./plugins');
|
||||||
|
|
||||||
(function(Posts) {
|
(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) {
|
Posts.getPostData = function(pid, callback) {
|
||||||
db.getObject('post:' + pid, function(err, data) {
|
db.getObject('post:' + pid, function(err, data) {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ var async = require('async'),
|
|||||||
meta = require('../meta'),
|
meta = require('../meta'),
|
||||||
websockets = require('../socket.io'),
|
websockets = require('../socket.io'),
|
||||||
postTools = require('../postTools'),
|
postTools = require('../postTools'),
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins')
|
||||||
privileges = require('../privileges');
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(Posts) {
|
module.exports = function(Posts) {
|
||||||
@@ -105,21 +104,4 @@ module.exports = function(Posts) {
|
|||||||
user.isModerator(uid, cids, callback);
|
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);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ var async = require('async'),
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
plugins.fireHook('action:user.set', {field: field, value: value, type: 'decrement'});
|
plugins.fireHook('action:user.set', {field: field, value: value, type: 'decrement'});
|
||||||
|
|
||||||
callback(null, value);
|
callback(null, value);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user