mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 17:05:51 +01:00
merge
This commit is contained in:
@@ -11,7 +11,6 @@ define('forum/account/watched', ['forum/account/header', 'forum/infinitescroll']
|
||||
};
|
||||
|
||||
function loadMore(direction) {
|
||||
console.log(direction);
|
||||
if (direction < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
140
src/groups.js
140
src/groups.js
@@ -299,7 +299,7 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
Groups.getMemberCount = function(groupName, callback) {
|
||||
db.sortedSetCard('group:' + groupName + ':members', callback);
|
||||
db.getObjectField('group:' + groupName, 'memberCount', callback);
|
||||
};
|
||||
|
||||
Groups.isMemberOfGroupList = function(uid, groupListKey, callback) {
|
||||
@@ -611,46 +611,56 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
Groups.join = function(groupName, uid, callback) {
|
||||
callback = callback || function() {};
|
||||
function join() {
|
||||
var tasks = [
|
||||
async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', Date.now(), uid),
|
||||
async.apply(db.incrObjectField, 'group:' + groupName, 'memberCount')
|
||||
];
|
||||
|
||||
Groups.exists(groupName, function(err, exists) {
|
||||
if (exists) {
|
||||
var tasks = [
|
||||
async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', Date.now(), uid)
|
||||
];
|
||||
|
||||
user.isAdministrator(uid, function(err, isAdmin) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
user.isAdministrator(uid, next);
|
||||
},
|
||||
function(isAdmin, next) {
|
||||
if (isAdmin) {
|
||||
tasks.push(async.apply(db.setAdd, 'group:' + groupName + ':owners', uid));
|
||||
}
|
||||
|
||||
async.parallel(tasks, function(err) {
|
||||
plugins.fireHook('action:group.join', {
|
||||
groupName: groupName,
|
||||
uid: uid
|
||||
});
|
||||
|
||||
callback();
|
||||
});
|
||||
async.parallel(tasks, next);
|
||||
}
|
||||
], function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
plugins.fireHook('action:group.join', {
|
||||
groupName: groupName,
|
||||
uid: uid
|
||||
});
|
||||
} else {
|
||||
Groups.create({
|
||||
name: groupName,
|
||||
description: '',
|
||||
hidden: 1
|
||||
}, function(err) {
|
||||
if (err && err.message !== '[[error:group-already-exists]]') {
|
||||
winston.error('[groups.join] Could not create new hidden group: ' + err.message);
|
||||
return callback(err);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
db.sortedSetAdd('group:' + groupName + ':members', Date.now(), uid, callback);
|
||||
plugins.fireHook('action:group.join', {
|
||||
groupName: groupName,
|
||||
uid: uid
|
||||
});
|
||||
});
|
||||
callback = callback || function() {};
|
||||
|
||||
Groups.exists(groupName, function(err, exists) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
return join();
|
||||
}
|
||||
|
||||
Groups.create({
|
||||
name: groupName,
|
||||
description: '',
|
||||
hidden: 1
|
||||
}, function(err) {
|
||||
if (err && err.message !== '[[error:group-already-exists]]') {
|
||||
winston.error('[groups.join] Could not create new hidden group: ' + err.message);
|
||||
return callback(err);
|
||||
}
|
||||
join();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -692,9 +702,10 @@ var async = require('async'),
|
||||
callback = callback || function() {};
|
||||
|
||||
var tasks = [
|
||||
async.apply(db.sortedSetRemove, 'group:' + groupName + ':members', uid),
|
||||
async.apply(db.setRemove, 'group:' + groupName + ':owners', uid)
|
||||
];
|
||||
async.apply(db.sortedSetRemove, 'group:' + groupName + ':members', uid),
|
||||
async.apply(db.setRemove, 'group:' + groupName + ':owners', uid),
|
||||
async.apply(db.decrObjectField, 'group:' + groupName, 'memberCount')
|
||||
];
|
||||
|
||||
async.parallel(tasks, function(err) {
|
||||
if (err) {
|
||||
@@ -715,7 +726,7 @@ var async = require('async'),
|
||||
if (group.hidden && group.memberCount === 0) {
|
||||
Groups.destroy(groupName, callback);
|
||||
} else {
|
||||
return callback();
|
||||
callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -786,46 +797,35 @@ var async = require('async'),
|
||||
return group;
|
||||
});
|
||||
|
||||
async.map(groupData, function(groupObj, next) {
|
||||
Groups.getMemberCount(groupObj.name, function(err, memberCount) {
|
||||
if (err) { return next(err); }
|
||||
|
||||
groupObj.memberCount = memberCount;
|
||||
next(err, groupObj);
|
||||
});
|
||||
}, function(err, groupData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
var groupSets = groupData.map(function(group) {
|
||||
group.labelColor = group.labelColor || '#000000';
|
||||
group.createtimeISO = utils.toISOString(group.createtime);
|
||||
|
||||
if (!group['cover:url']) {
|
||||
group['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png';
|
||||
group['cover:position'] = '50% 50%';
|
||||
}
|
||||
|
||||
var groupSets = groupData.map(function(group) {
|
||||
group.labelColor = group.labelColor || '#000000';
|
||||
return 'group:' + group.name + ':members';
|
||||
});
|
||||
|
||||
if (!group['cover:url']) {
|
||||
group['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png';
|
||||
group['cover:position'] = '50% 50%';
|
||||
async.map(uids, function(uid, next) {
|
||||
db.isMemberOfSortedSets(groupSets, uid, function(err, isMembers) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
return 'group:' + group.name + ':members';
|
||||
});
|
||||
|
||||
async.map(uids, function(uid, next) {
|
||||
db.isMemberOfSortedSets(groupSets, uid, function(err, isMembers) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
var memberOf = [];
|
||||
isMembers.forEach(function(isMember, index) {
|
||||
if (isMember) {
|
||||
memberOf.push(groupData[index]);
|
||||
}
|
||||
|
||||
var memberOf = [];
|
||||
isMembers.forEach(function(isMember, index) {
|
||||
if (isMember) {
|
||||
memberOf.push(groupData[index]);
|
||||
}
|
||||
});
|
||||
|
||||
next(null, memberOf);
|
||||
});
|
||||
}, callback);
|
||||
});
|
||||
|
||||
next(null, memberOf);
|
||||
});
|
||||
}, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ var db = require('./database'),
|
||||
schemaDate, thisSchemaDate,
|
||||
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
latestSchema = Date.UTC(2015, 0, 21);
|
||||
latestSchema = Date.UTC(2015, 0, 30);
|
||||
|
||||
Upgrade.check = function(callback) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
@@ -773,6 +773,41 @@ Upgrade.upgrade = function(callback) {
|
||||
winston.info('[2015/01/21] Upgrading groups to sorted set skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = Date.UTC(2015, 0, 30);
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
winston.info('[2015/01/30] Adding group member counts');
|
||||
|
||||
db.getSortedSetRange('groups:createtime', 0, -1, function(err, groupNames) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var now = Date.now();
|
||||
async.each(groupNames, function(groupName, next) {
|
||||
db.sortedSetCard('group:' + groupName + ':members', function(err, memberCount) {
|
||||
console.log(groupName, memberCount);
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (parseInt(memberCount, 10)) {
|
||||
db.setObjectField('group:' + groupName, 'memberCount', memberCount, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
}, function(err) {
|
||||
winston.info('[2015/01/30] Adding group member counts done');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2015/01/30] Adding group member counts skipped');
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
// Add new schema updates here
|
||||
|
||||
Reference in New Issue
Block a user