upgrade script, and fixed client-side generation of user icon

v1.18.x
Julian Lam 9 years ago
parent 9120cb8e82
commit a43d40fbc7

@ -349,7 +349,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
$('#user-uploaded-picture').attr('src', uploadedPicture);
}
$('#default-box').toggle(true).find('.user-icon').css('background-color', ajaxify.data['icon:bgColor']).text(ajaxify.data['username'].slice(0, 1));
$('#default-box').toggle(true).find('.user-icon').css('background-color', ajaxify.data['icon:bgColor']).text(ajaxify.data['username'].slice(0, 1).toUpperCase());
$('#uploaded-box').toggle(!!uploadedPicture);
$('#default-box .fa-check').toggle(currentPicture !== uploadedPicture);

@ -21,7 +21,7 @@ var db = require('./database'),
schemaDate, thisSchemaDate,
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
latestSchema = Date.UTC(2015, 7, 18);
latestSchema = Date.UTC(2015, 8, 27);
Upgrade.check = function(callback) {
db.get('schemaDate', function(err, value) {
@ -486,6 +486,27 @@ Upgrade.upgrade = function(callback) {
winston.info('[2015/08/18] Creating children category sorted sets skipped');
next();
}
},
function(next) {
thisSchemaDate = Date.UTC(2015, 8, 27);
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2015/09/27] Generating user icons');
db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) {
async.eachLimit(uids, 20, User.icon.generate, function(err) {
if (err) {
return next(err);
}
winston.info('[2015/09/27] Generating user icons done');
Upgrade.update(thisSchemaDate, next);
})
})
} else {
winston.info('[2015/09/27] Generating user icons skipped');
next();
}
}

@ -8,7 +8,7 @@ module.exports = function(User) {
User.icon.generate = function(uid, callback) {
// For convenience, only backgrounds that work well with white as used
var backgrounds = ['#AB4642', '#DC9656', '#A1B56C', '#7CAFC2', '#BA8BAF', '#A16946'],
bgColor = backgrounds[Math.floor(Math.random() * backgrounds.length) + 1];
bgColor = backgrounds[Math.floor(Math.random() * backgrounds.length)];
User.getUserField(uid, 'username', function(err, username) {
User.setUserFields(uid, {

Loading…
Cancel
Save