diff --git a/src/groups/membership.js b/src/groups/membership.js index 8ffd845443..48bb82f56f 100644 --- a/src/groups/membership.js +++ b/src/groups/membership.js @@ -251,6 +251,9 @@ module.exports = function (Groups) { next(); } }, + function (next) { + clearGroupTitleIfSet(groupName, uid, next); + }, function (next) { plugins.fireHook('action:group.leave', { groupName: groupName, @@ -261,6 +264,24 @@ module.exports = function (Groups) { ], callback); }; + function clearGroupTitleIfSet(groupName, uid, callback) { + if (groupName === 'registered-users' || Groups.isPrivilegeGroup(groupName)) { + return callback(); + } + async.waterfall([ + function (next) { + db.getObjectField('user:' + uid, 'groupTitle', next); + }, + function (groupTitle, next) { + if (groupTitle === groupName) { + db.deleteObjectField('user:' + uid, 'groupTitle', next); + } else { + next(); + } + } + ], callback); + } + Groups.leaveAllGroups = function (uid, callback) { async.waterfall([ function (next) {