diff --git a/public/templates/home.tpl b/public/templates/home.tpl index 5b6d73797f..23675bd306 100644 --- a/public/templates/home.tpl +++ b/public/templates/home.tpl @@ -3,7 +3,7 @@
  • {topics.title}

    -

    Posted {topics.relativeTime} by user {topics.uid}. {topics.post_count} posts.

    +

    Posted {topics.relativeTime} by {topics.uid}. {topics.post_count} posts.

  • @@ -17,13 +17,13 @@ jQuery('document').ready(function() { jQuery('.username').each(function() { var userId = this.innerHTML; - socket.on('api:user.get', function(userObj) { - console.log("derp"); - console.log(userObj); - - }); + (function(span){ + socket.on('api:user.getNameByUid', function(username) { + span.innerHTML = username; + }); + })(this); - socket.emit('api:user.get', { fields: [ 'uid' ], 'uid': userId }); + socket.emit('api:user.getNameByUid', { fields: [ 'username' ], 'uid': userId }); }) diff --git a/src/user.js b/src/user.js index fcded28330..0b4d22913b 100644 --- a/src/user.js +++ b/src/user.js @@ -262,6 +262,10 @@ var config = require('../config.js'), RDB.get('username:' + username + ':uid', callback); }; + User.get_username_by_uid = function(uid, callback) { + RDB.get('uid:' + uid+ ':username', callback); + }; + User.get_uid_by_email = function(email, callback) { RDB.get('email:' + email, callback) }; diff --git a/src/websockets.js b/src/websockets.js index eff9118aa9..17018a4f70 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -70,7 +70,13 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}), // BEGIN: API calls (todo: organize) // julian: :^) socket.on('api:user.get', function(data) { - modules.user.get(socket, data.uid || uid, data.fields); + modules.user.get(socket, uid, data.fields); + }); + + socket.on('api:user.getNameByUid', function(data) { + modules.user.get_username_by_uid(data.uid, function(data){ + socket.emit('api:user.getNameByUid', data); + }); }); socket.on('user.exists', function(data) {