facebook like chat

I've created a simple chat with socket.io. I decided to go ahead and create facebook like chat. The problems:

  1. Each user has his own online friends and how to show to user his own online friends
  2. How and where store users and their messages
  3. Update buddy list of certain user if somebody of his freinds disconnects
  4. How to emit an event only to friends of a specific person (not to all connected users)

You can check these plugin for jquery and pusher (api for pushing notifications). It will help you with some of the client side work, just read the code. It will help you to make your own one.

http://html5-ninja.com/item/Pusher-Chat-jQuery-plugin/7

Unless you're doing this as just an exercise to yourself, I would say that you're making it way too difficult or yourself to build all this (and you're not even adressing the most important question here: what to do when the whole thing doesn't fit on one server anymore).

I would say, install one of the many XMPP servers out there that solve all these problems for you.

If you ARE doing this just for an exercise, I would still say, look at XMPP. It has standards for which messages to send (for 1 and 3). 2: just store them in some database. Be prepared for some major database issues if you have more than 50 database write actions / second. And for 4: just loop over all online friends of some user if you want to send them the disconnect.