Node.js based forum software built for the modern web
refactored the groups update method a bit, and now if a group has pending members and it becomes a public group, those users become members
Julian Lam081462983a2b
diff --git a/src/groups.js b/src/groups.jsindex 7567c662f5..f82e452b96 100644--- a/src/groups.js+++ b/src/groups.js@@ -503,7 +503,11 @@ var async = require('async'),'private': values.private === false ? '0' : '1'};- db.setObject('group:' + groupName, payload, function(err) {+ async.series([+ async.apply(updatePrivacy, groupName, values.private),+ async.apply(db.setObject, 'group:' + groupName, payload),+ async.apply(renameGroup, groupName, values.name)+ ], function(err) {if (err) {return callback(err);}@@ -512,11 +516,37 @@ var async = require('async'),name: groupName,values: values});- renameGroup(groupName, values.name, callback);+ callback();});});};+ function updatePrivacy(groupName, newValue, callback) {+ // Grab the group's current privacy value+ Groups.getGroupFields(groupName, ['private'], function(err, currentValue) {+ currentValue = currentValue.private === '1'; // Now a Boolean++ if (currentValue !== newValue && currentValue === true) {+ // Group is now public, so all pending users are automatically considered members+ db.getSetMembers('group:' + groupName + ':pending', function(err, uids) {+ if (err) { return callback(err); }+ else if (!uids) { return callback(); } // No pending users, we're good to go++ var now = Date.now(),+ scores = uids.map(function() { return now; }); // There's probably a better way to initialise an Array of size x with the same value...++ winston.verbose('[groups.update] Group is now public, automatically adding ' + uids.length + ' new members, who were pending prior.');+ async.series([+ async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', scores, uids),+ async.apply(db.delete, 'group:' + groupName + ':pending')+ ], callback);+ });+ } else {+ callback();+ }+ });+ }+function renameGroup(oldName, newName, callback) {if (oldName === newName || !newName || newName.length === 0) {return callback();