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 -->
<a href="topic/{topics.slug}"><li class="topic-row">
<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>
<!-- END topics -->
</ul>
@ -14,6 +14,22 @@ 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 });
})
});

@ -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,10 +26,15 @@ 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);
});
@ -39,6 +42,10 @@ var SocketIO = require('socket.io').listen(global.server),
io.sockets.on('connection', function(socket) {
var hs = socket.handshake;
var uid = users[hs.sessionID];
if (DEVELOPMENT === true) {
// refreshing templates
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: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) {

Loading…
Cancel
Save