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

@ -6,6 +6,7 @@
user = require('./user'),
meta = require('./meta'),
db = require('./database'),
posts = require('./posts'),
utils = require('../public/src/utils'),
ephemeralGroups = ['guests'],
@ -304,4 +305,21 @@
}, 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));

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

Loading…
Cancel
Save