Skip to content

Node.js based forum software built for the modern web

resolved #868

Julian Lamd360a9bcacd5
diff --git a/src/groups.js b/src/groups.js
index f0541f824f..8d9b50067c 100644
--- a/src/groups.js
+++ b/src/groups.js
@@ -86,6 +86,24 @@
});
};
+ Groups.getMemberships = function(uid, callback) {
+ if (!uid) {
+ return callback(new Error('no-uid-specified'));
+ }
+
+ db.getObjectValues('group:gid', function(err, gids) {
+ async.filter(gids, function(gid, next) {
+ Groups.isMember(uid, gid, function(err, isMember) {
+ next(isMember);
+ });
+ }, function(gids) {
+ async.map(gids, function(gid, next) {
+ Groups.get(gid, {}, next);
+ }, callback);
+ });
+ });
+ };
+
Groups.isDeleted = function(gid, callback) {
db.getObjectField('gid:' + gid, 'deleted', function(err, deleted) {
callback(err, parseInt(deleted, 10) === 1);
diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js
new file mode 100644
index 0000000000..368a48f709
--- /dev/null
+++ b/src/socket.io/groups.js
@@ -0,0 +1,11 @@
+var Groups = require('../groups'),
+
+ SocketGroups = {};
+
+SocketGroups.getMemberships = function(socket, data, callback) {
+ if (data && data.uid) {
+ Groups.getMemberships(data.uid, callback);
+ }
+};
+
+module.exports = SocketGroups;
\ No newline at end of file