Skip to content

Node.js based forum software built for the modern web

show username on homepage

Baris Usaklied26728a0f7b
diff --git a/public/templates/home.tpl b/public/templates/home.tpl
index 23675bd306..8be6975834 100644
--- a/public/templates/home.tpl
+++ b/public/templates/home.tpl
@@ -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 });
-
- })
-
-
diff --git a/src/topics.js b/src/topics.js
index 6f92688c0e..01f1849a3b 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -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([]);
diff --git a/src/user.js b/src/user.js
index 0b4d22913b..80cf5c822a 100644
--- a/src/user.js
+++ b/src/user.js
@@ -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)
};