gravatars in posts

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

@ -10,7 +10,7 @@
<li class="row"> <li class="row">
<div class="span1 profile-image-block"> <div class="span1 profile-image-block">
<!--<i class="icon-spinner icon-spin icon-2x pull-left"></i>--> <!--<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 <i class="icon-star"></i>2432
</div> </div>
<div class="span11"> <div class="span11">

@ -43,19 +43,22 @@ var RDB = require('./redis.js'),
timestamp = replies[2]; timestamp = replies[2];
user.get_usernames_by_uids(uid, function(userNames) { user.get_usernames_by_uids(uid, function(userNames) {
var posts = []; user.get_gravatars_by_uids(uid, 80, function(gravatars) {
for (var i=0, ii=content.length; i<ii; i++) { var posts = [];
posts.push({ for (var i=0, ii=content.length; i<ii; i++) {
'pid' : pid[i], posts.push({
'content' : marked(content[i]), 'pid' : pid[i],
'uid' : uid[i], 'content' : marked(content[i]),
'userName' : userNames[i] || 'anonymous', 'uid' : uid[i],
'timestamp' : timestamp[i], 'userName' : userNames[i] || 'anonymous',
'relativeTime': utils.relativeTime(timestamp[i]) 'gravatar' : gravatars[i],
}); 'timestamp' : timestamp[i],
} 'relativeTime': utils.relativeTime(timestamp[i])
});
callback({'topic_name':topic_name, 'topic_id': tid, 'posts': posts}); }
callback({'topic_name':topic_name, 'topic_id': tid, 'posts': posts});
});
}); });
}); });
} else { } 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) { User.login = function(socket, user) {
if (user.username == null || user.password == null) { if (user.username == null || user.password == null) {
return socket.emit('user.login', {'status': 0, 'message': 'Missing fields'}); return socket.emit('user.login', {'status': 0, 'message': 'Missing fields'});

Loading…
Cancel
Save