From 51c520f888b37a832957e4e0668ce133d2ab0e2f Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 30 Nov 2014 12:52:16 -0500 Subject: [PATCH] closes #2480 --- src/groups.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/groups.js b/src/groups.js index cbdc55c32b..780b38a77d 100644 --- a/src/groups.js +++ b/src/groups.js @@ -8,6 +8,7 @@ var async = require('async'), db = require('./database'), plugins = require('./plugins'), posts = require('./posts'), + privileges = require('./privileges'), utils = require('../public/src/utils'); @@ -525,23 +526,26 @@ var async = require('async'), }; Groups.getLatestMemberPosts = function(groupName, max, uid, callback) { - Groups.get(groupName, {}, function(err, groupObj) { - if (err || parseInt(groupObj.memberCount, 10) === 0) { - return callback(null, []); - } - - var keys = groupObj.members.map(function(uid) { - return 'uid:' + uid + ':posts'; - }); - - db.getSortedSetRevUnion(keys, 0, max-1, function(err, pids) { - if (err) { - return callback(err); + async.waterfall([ + function(next) { + Groups.getMembers(groupName, next); + }, + function(uids, next) { + if (!Array.isArray(uids) || !uids.length) { + return callback(null, []); } - - posts.getPostSummaryByPids(pids, uid, {stripTags: false}, callback); - }); - }); + var keys = uids.map(function(uid) { + return 'uid:' + uid + ':posts'; + }); + db.getSortedSetRevUnion(keys, 0, max - 1, next); + }, + function(pids, next) { + privileges.posts.filter('read', pids, uid, next); + }, + function(pids, next) { + posts.getPostSummaryByPids(pids, uid, {stripTags: false}, next); + } + ], callback); }; Groups.getUserGroups = function(uids, callback) {