Node.js based forum software built for the modern web
use getPostsFromSet for recent replies
barisusakli21459fff84b1
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.jsindex 4dfcf86fa5..23f6560be5 100644--- a/src/categories/recentreplies.js+++ b/src/categories/recentreplies.js@@ -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 : []);});};diff --git a/src/posts.js b/src/posts.jsindex 9a66c3d5ec..4144367564 100644--- a/src/posts.js+++ b/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) {diff --git a/src/posts/user.js b/src/posts/user.jsindex 3b6f2e9e20..2799e4298d 100644--- a/src/posts/user.js+++ b/src/posts/user.js@@ -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);- };};diff --git a/src/user.js b/src/user.jsindex 9f3f81cd98..2c3b3386f9 100644--- a/src/user.js+++ b/src/user.js@@ -178,7 +178,7 @@ var async = require('async'),if (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);});