finished up group list and group details pages - closed #1563

v1.18.x
Julian Lam 11 years ago
parent 7afe3bea59
commit f20926f93d

@ -2,5 +2,7 @@
"view_group": "View Group", "view_group": "View Group",
"details.title": "Group Details", "details.title": "Group Details",
"details.members": "Member List" "details.members": "Member List",
"details.has_no_posts": "This group's members have not made any posts.",
"details.latest_posts": "Latest Posts"
} }

@ -1,6 +1,7 @@
"use strict"; "use strict";
var groups = require('../groups'), var groups = require('../groups'),
async = require('async'),
groupsController = {}; groupsController = {};
@ -9,7 +10,6 @@ groupsController.list = function(req, res) {
truncateUserList: true, truncateUserList: true,
expand: true expand: true
}, function(err, groups) { }, function(err, groups) {
console.log(groups);
res.render('groups/list', { res.render('groups/list', {
groups: groups groups: groups
}); });
@ -17,11 +17,18 @@ groupsController.list = function(req, res) {
}; };
groupsController.details = function(req, res) { groupsController.details = function(req, res) {
groups.get(req.params.name, { async.parallel({
expand: true group: function(next) {
}, function(err, groupObj) { groups.get(req.params.name, {
expand: true
}, next);
},
posts: function(next) {
groups.getLatestMemberPosts(req.params.name, 10, next);
}
}, function(err, results) {
if (!err) { if (!err) {
res.render('groups/details', groupObj); res.render('groups/details', results);
} else { } else {
res.redirect('404'); res.redirect('404');
} }

@ -6,6 +6,7 @@
user = require('./user'), user = require('./user'),
meta = require('./meta'), meta = require('./meta'),
db = require('./database'), db = require('./database'),
posts = require('./posts'),
utils = require('../public/src/utils'), utils = require('../public/src/utils'),
ephemeralGroups = ['guests'], ephemeralGroups = ['guests'],
@ -304,4 +305,21 @@
}, callback); }, callback);
}); });
}; };
Groups.getLatestMemberPosts = function(groupName, max, 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) {
posts.getPostSummaryByPids(pids, false, function(err, posts) {
callback(null, posts);
})
})
});
}
}(module.exports)); }(module.exports));

@ -54,10 +54,9 @@ module.exports = function(app, middleware, controllers) {
}); });
app.get('/test', function(req, res) { app.get('/test', function(req, res) {
var db = require('../database'); var a = require('../groups');
db.getSortedSetUnion(['uid:1:posts', 'uid:3:posts'], function(err, pids) { a.getLatestMemberPosts('mcg', 5, function() {
console.log(err); res.json(arguments);
res.json(pids);
}); });
}); });
}); });

Loading…
Cancel
Save