diff --git a/public/templates/home.tpl b/public/templates/home.tpl index b49f4c2e85..5b6d73797f 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 user {topics.uid}. {topics.post_count} posts.

  • @@ -14,7 +14,23 @@ new_post.onclick = function() { } 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); + + }); + + socket.emit('api:user.get', { fields: [ 'uid' ], 'uid': userId }); + + }) + + + + + }); diff --git a/src/websockets.js b/src/websockets.js index b5370b84aa..eff9118aa9 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -1,13 +1,11 @@ -var SocketIO = require('socket.io').listen(global.server), +var SocketIO = require('socket.io').listen(global.server,{log:false}), cookie = require('cookie'), connect = require('connect'), config = require('../config.js'); (function(io) { var modules = null, - sessionID, - uid; - + users = {}; global.io = io; module.exports.init = function() { modules = global.modules; @@ -28,16 +26,25 @@ var SocketIO = require('socket.io').listen(global.server), } // Otherwise, continue unimpeded. - sessionID = handshakeData.sessionID; - global.modules.user.get_uid_by_session(sessionID, function(session_uid) { - if (session_uid) uid = session_uid; - else uid = 0; + var sessionID = handshakeData.sessionID; + + global.modules.user.get_uid_by_session(sessionID, function(userId) { + if (userId) + { + users[sessionID] = userId; + } + else + users[sessionID] = 0; accept(null, true); }); }); io.sockets.on('connection', function(socket) { + + var hs = socket.handshake; + + var uid = users[hs.sessionID]; if (DEVELOPMENT === true) { // refreshing templates @@ -49,14 +56,21 @@ var SocketIO = require('socket.io').listen(global.server), console.log("error message "+err); socket.emit('event:consolelog',{type:'uncaughtException', stack:err.stack, error:err.toString()}); }); - socket.emit('event:connect', {status: 1}); + socket.on('disconnect', function() { + console.log('Got disconnect! SESSION ID : '+hs.sessionID+' USER ID : '+uid); + + delete users[hs.sessionID]; + console.log(users); + }); + + // BEGIN: API calls (todo: organize) // julian: :^) socket.on('api:user.get', function(data) { - modules.user.get(socket, uid, data.fields); + modules.user.get(socket, data.uid || uid, data.fields); }); socket.on('user.exists', function(data) {