Skip to content

Node.js based forum software built for the modern web

updated to no longer use user.icons.generate, and removed an unneeded upgrade script! :)

Julian Lam9f6dc63fedc8
diff --git a/src/upgrade.js b/src/upgrade.js
index 9e8636c6d4..b726e40689 100644
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@ -487,27 +487,6 @@ Upgrade.upgrade = function(callback) {
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();
- }
- },
function(next) {
thisSchemaDate = Date.UTC(2015, 8, 30);
if (schemaDate < thisSchemaDate) {
diff --git a/src/user.js b/src/user.js
index f2ba5e233b..c3ef41a6eb 100644
--- a/src/user.js
+++ b/src/user.js
@@ -33,7 +33,6 @@ var async = require('async'),
require('./user/picture')(User);
require('./user/approval')(User);
require('./user/invite')(User);
- require('./user/icon')(User);
require('./user/password')(User);
User.updateLastOnlineTime = function(uid, callback) {
diff --git a/src/user/create.js b/src/user/create.js
index d6b8d87d35..9beca877f4 100644
--- a/src/user/create.js
+++ b/src/user/create.js
@@ -126,8 +126,7 @@ module.exports = function(User) {
async.apply(User.reset.updateExpiry, userData.uid)
], next);
});
- },
- async.apply(User.icon.generate, userData.uid)
+ }
], next);
},
function(results, next) {
diff --git a/src/user/data.js b/src/user/data.js
index 5d30060019..d9bad4f086 100644
--- a/src/user/data.js
+++ b/src/user/data.js
@@ -113,6 +113,13 @@ module.exports = function(User) {
for(var i=0; i<fieldsToRemove.length; ++i) {
user[fieldsToRemove[i]] = undefined;
}
+
+ // User Icons
+ var backgrounds = ['#AB4642', '#DC9656', '#A1B56C', '#7CAFC2', '#BA8BAF', '#A16946'];
+ user['icon:text'] = (user.username[0] || '').toUpperCase();
+ user['icon:bgColor'] = backgrounds[Array.prototype.reduce.call(user.username, function(cur, next) {
+ return cur + next.charCodeAt();
+ }, 0) % backgrounds.length];
});
plugins.fireHook('filter:users.get', users, callback);
diff --git a/src/user/icon.js b/src/user/icon.js
deleted file mode 100644
index fbf9274492..0000000000
--- a/src/user/icon.js
+++ /dev/null
@@ -1,20 +0,0 @@
-'use strict';
-
-var async = require('async');
-
-module.exports = function(User) {
- User.icon = {};
-
- 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)];
-
- User.getUserField(uid, 'username', function(err, username) {
- User.setUserFields(uid, {
- 'icon:text': username.slice(0, 1).toUpperCase(),
- 'icon:bgColor': bgColor
- }, callback);
- })
- }
-};
\ No newline at end of file