Merge branch 'master' of github.com:psychobunny/node-forum

v1.18.x
Julian Lam 12 years ago
commit daa01d07d2

@ -3,7 +3,7 @@
<!-- BEGIN topics --> <!-- BEGIN topics -->
<a href="topic/{topics.slug}"><li class="topic-row"> <a href="topic/{topics.slug}"><li class="topic-row">
<h4>{topics.title}</h4> <h4>{topics.title}</h4>
<p>Posted {topics.relativeTime} by user {topics.uid}. {topics.post_count} posts.</p> <p>Posted {topics.relativeTime} by user <span class="username">{topics.uid}</span>. {topics.post_count} posts.</p>
</li></a> </li></a>
<!-- END topics --> <!-- END topics -->
</ul> </ul>
@ -14,6 +14,22 @@ new_post.onclick = function() {
} }
jQuery('document').ready(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 });
})
}); });

@ -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'), cookie = require('cookie'),
connect = require('connect'), connect = require('connect'),
config = require('../config.js'); config = require('../config.js');
(function(io) { (function(io) {
var modules = null, var modules = null,
sessionID, users = {};
uid;
global.io = io; global.io = io;
module.exports.init = function() { module.exports.init = function() {
modules = global.modules; modules = global.modules;
@ -28,10 +26,15 @@ var SocketIO = require('socket.io').listen(global.server),
} }
// Otherwise, continue unimpeded. // Otherwise, continue unimpeded.
sessionID = handshakeData.sessionID; var sessionID = handshakeData.sessionID;
global.modules.user.get_uid_by_session(sessionID, function(session_uid) {
if (session_uid) uid = session_uid; global.modules.user.get_uid_by_session(sessionID, function(userId) {
else uid = 0; if (userId)
{
users[sessionID] = userId;
}
else
users[sessionID] = 0;
accept(null, true); accept(null, true);
}); });
@ -39,6 +42,10 @@ var SocketIO = require('socket.io').listen(global.server),
io.sockets.on('connection', function(socket) { io.sockets.on('connection', function(socket) {
var hs = socket.handshake;
var uid = users[hs.sessionID];
if (DEVELOPMENT === true) { if (DEVELOPMENT === true) {
// refreshing templates // refreshing templates
modules.templates.init(); modules.templates.init();
@ -50,13 +57,20 @@ var SocketIO = require('socket.io').listen(global.server),
socket.emit('event:consolelog',{type:'uncaughtException', stack:err.stack, error:err.toString()}); socket.emit('event:consolelog',{type:'uncaughtException', stack:err.stack, error:err.toString()});
}); });
socket.emit('event:connect', {status: 1}); 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) // BEGIN: API calls (todo: organize)
// julian: :^) // julian: :^)
socket.on('api:user.get', function(data) { 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) { socket.on('user.exists', function(data) {

Loading…
Cancel
Save