gravatars in posts

v1.18.x
psychobunny 12 years ago
parent 2bc9876852
commit 7db1834182

@ -10,7 +10,7 @@
<li class="row">
<div class="span1 profile-image-block">
<!--<i class="icon-spinner icon-spin icon-2x pull-left"></i>-->
<img src="https://en.gravatar.com/userimage/18452752/f59e713c717466d2f5ad2a6970769f32.png" align="left" />
<img src="{posts.gravatar}" align="left" />
<i class="icon-star"></i>2432
</div>
<div class="span11">

@ -43,19 +43,22 @@ var RDB = require('./redis.js'),
timestamp = replies[2];
user.get_usernames_by_uids(uid, function(userNames) {
var posts = [];
for (var i=0, ii=content.length; i<ii; i++) {
posts.push({
'pid' : pid[i],
'content' : marked(content[i]),
'uid' : uid[i],
'userName' : userNames[i] || 'anonymous',
'timestamp' : timestamp[i],
'relativeTime': utils.relativeTime(timestamp[i])
});
}
callback({'topic_name':topic_name, 'topic_id': tid, 'posts': posts});
user.get_gravatars_by_uids(uid, 80, function(gravatars) {
var posts = [];
for (var i=0, ii=content.length; i<ii; i++) {
posts.push({
'pid' : pid[i],
'content' : marked(content[i]),
'uid' : uid[i],
'userName' : userNames[i] || 'anonymous',
'gravatar' : gravatars[i],
'timestamp' : timestamp[i],
'relativeTime': utils.relativeTime(timestamp[i])
});
}
callback({'topic_name':topic_name, 'topic_id': tid, 'posts': posts});
});
});
});
} else {

@ -48,6 +48,33 @@ var config = require('../config.js'),
}
}
User.get_gravatars_by_uids = function(uids, size, callback) {
var keys = [];
for (var i = 0, ii= uids.length; i<ii; i++) {
keys.push('uid:' + uids[i] + ':email');
}
var gravatars = [];
RDB.mget(keys, function(data) {
for (var i=0, ii=data.length; i<ii; i++) {
if (!data[i]) {
gravatars.push("http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=" + size);
} else {
var md5sum = crypto.createHash('md5');
md5sum.update((data[i]).toLowerCase());
gravatars.push('http://www.gravatar.com/avatar/' + md5sum.digest('hex') + '?s=' + size);
}
}
callback(gravatars);
});
};
User.login = function(socket, user) {
if (user.username == null || user.password == null) {
return socket.emit('user.login', {'status': 0, 'message': 'Missing fields'});

Loading…
Cancel
Save