diff --git a/public/src/helpers.js b/public/src/helpers.js
index a89aeae0e2..38875ea8b8 100644
--- a/public/src/helpers.js
+++ b/public/src/helpers.js
@@ -17,6 +17,19 @@
return '';
};
+ // Groups helpers
+ helpers.membershipBtn = function(groupObj) {
+ if (groupObj.isMember) {
+ return '';
+ } else {
+ if (groupObj.pending) {
+ return '';
+ } else {
+ return '';
+ }
+ }
+ };
+
if ('undefined' !== typeof window) {
$(document).ready(module.exports);
}
@@ -26,6 +39,7 @@
templates.registerHelper('displayUsersLink', helpers.displayUsersLink);
templates.registerHelper('buildMetaTag', helpers.buildMetaTag);
+ templates.registerHelper('membershipBtn', helpers.membershipBtn);
};
})('undefined' === typeof module ? {
diff --git a/src/controllers/groups.js b/src/controllers/groups.js
index 3843672a09..72d83d4fc2 100644
--- a/src/controllers/groups.js
+++ b/src/controllers/groups.js
@@ -9,7 +9,8 @@ var groups = require('../groups'),
groupsController.list = function(req, res, next) {
groups.list({
truncateUserList: true,
- expand: true
+ expand: true,
+ uid: req.user ? req.user.uid : 0
}, function(err, groups) {
if (err) {
return next(err);
diff --git a/src/groups.js b/src/groups.js
index 47e7002db9..4f59d39820 100644
--- a/src/groups.js
+++ b/src/groups.js
@@ -71,7 +71,25 @@ var async = require('async'),
groupNames = groupNames.concat(ephemeralGroups);
async.map(groupNames, function (groupName, next) {
- Groups.get(groupName, options, next);
+ async.waterfall([
+ async.apply(Groups.get, groupName, options),
+ function(groupObj, next) {
+ // Retrieve group membership state, if uid is passed in
+ if (!options.uid) {
+ return next(null, groupObj);
+ }
+
+ Groups.isMember(options.uid, groupName, function(err, isMember) {
+ if (err) {
+ winston.warn('[groups.list] Could not determine membership in group `' + groupName + '` for uid `' + options.uid + '`: ' + err.message);
+ return next(null, groupObj);
+ }
+
+ groupObj.isMember = isMember;
+ next(null, groupObj);
+ });
+ }
+ ], next);
}, function (err, groups) {
callback(err, internals.filterGroups(groups, options));
});