show username on homepage

v1.18.x
Baris Usakli 12 years ago
parent abf4be488a
commit ed26728a0f

@ -3,7 +3,7 @@
<!-- BEGIN topics -->
<a href="topic/{topics.slug}"><li class="topic-row">
<h4>{topics.title}</h4>
<p>Posted {topics.relativeTime} by <span class="username">{topics.uid}</span>. {topics.post_count} posts.</p>
<p>Posted {topics.relativeTime} by <span class="username">{topics.username}</span>. {topics.post_count} posts.</p>
</li></a>
<!-- END topics -->
</ul>
@ -14,20 +14,6 @@ new_post.onclick = function() {
}
jQuery('document').ready(function() {
jQuery('.username').each(function() {
var userId = this.innerHTML;
(function(span){
socket.on('api:user.getNameByUid', function(username) {
span.innerHTML = username;
});
})(this);
socket.emit('api:user.getNameByUid', { fields: [ 'username' ], 'uid': userId });
})

@ -1,6 +1,7 @@
var RDB = require('./redis.js'),
posts = require('./posts.js'),
utils = require('./utils.js');
utils = require('./utils.js'),
user = require('./user.js');
(function(Topics) {
//data structure
@ -68,25 +69,33 @@ var RDB = require('./redis.js'),
.mget(slug)
.mget(postcount)
.exec(function(err, replies) {
title = replies[0];
uid = replies[1];
timestamp = replies[2];
slug = replies[3];
postcount = replies[4];
var topics = [];
for (var i=0, ii=title.length; i<ii; i++) {
topics.push({
'title' : title[i],
'uid' : uid[i],
'timestamp' : timestamp[i],
'relativeTime': utils.relativeTime(timestamp[i]),
'slug' : slug[i],
'post_count' : postcount[i]
});
}
callback({'topics': topics});
user.get_usernames_by_uids(uid, function(userNames) {
var topics = [];
for (var i=0, ii=title.length; i<ii; i++) {
topics.push({
'title' : title[i],
'uid' : uid[i],
'username': userNames[i],
'timestamp' : timestamp[i],
'relativeTime': utils.relativeTime(timestamp[i]),
'slug' : slug[i],
'post_count' : postcount[i]
});
}
callback({'topics': topics});
});
}
);
} else callback([]);

@ -266,6 +266,17 @@ var config = require('../config.js'),
RDB.get('uid:' + uid+ ':username', callback);
};
User.get_usernames_by_uids = function(uids, callback) {
var userIds = [];
for(var i=0, ii=uids.length; i<ii; i++) {
userIds.push('uid:' + uids[i] + ':username');
}
RDB.mget(userIds, function(data) {
callback(data);
});
};
User.get_uid_by_email = function(email, callback) {
RDB.get('email:' + email, callback)
};

Loading…
Cancel
Save