|
// model is defined using the browserified client |
|
var ChatRoom = app.models.ChatRoom; |
|
var User = app.models.User; |
|
|
|
function login(username, password, cb) { |
|
User.login( |
|
{ username: username, password: password}, |
|
function(err, token) { |
|
if (err) return cb(err); |
|
ChatRoom.find(function(err, allRooms) { |
|
if (err) return cb(err); |
|
|
|
// TODO: GUI - render list of rooms |
|
|
|
ChatRoom.on('changed', function(room) { |
|
// TODO: GUI - add a new room to the list |
|
}); |
|
|
|
ChatRoom.on('deleted', function(roomId) { |
|
// TODO: GUI - remove the room from a list |
|
}); |
|
cb(); |
|
}); |
|
}); |
|
} |
|
|
|
function join(room, cb) { |
|
room.join(function(err) { |
|
if (err) return cb(err); |
|
|
|
async.parallel([ |
|
function fetchPosts(next) { |
|
room.posts(function(err, posts) { |
|
if (err) return next(err); |
|
|
|
// TODO: GUI - render a list of existing posts |
|
|
|
room.on('posted', function(post) { |
|
// TODO: GUI - add the new post to the chat window |
|
}); |
|
|
|
next(); |
|
}); |
|
}, |
|
|
|
function fetchUsers(next) { |
|
room.users(function(err, users) { |
|
if (err) return next(err); |
|
|
|
// TODO: GUI - render a list of users |
|
|
|
room.on('joined', function(user) { |
|
// TODO: add user to the list of connected users |
|
}); |
|
|
|
next(); |
|
}); |
|
}, |
|
], cb); |
|
}; |
|
} |
|
|
|
function post(room, message, cb) { |
|
room.post(message, function(err, msg) { |
|
if (err) return cb(err); |
|
// TODO: GUI - add the new post to the chat window |
|
cb(); |
|
}); |
|
} |