Question

Here's the idea.

I'm coding a chat bar, I have everything functioning. But my issue is keeping everything continuous whilst browsing pages across the site. By this I mean, chat boxes staying open. Like Facebook, as on Facebook, every time you open up a chat box and then navigate to a different page, it stays open, you don't have to go back into your online friends list and load of the chat box.

What have I done so far?

One method I have thought of using is using cookies to store the ID of the conversation in a cookie and put whether it is open or closed. So if a conversation has an ID of 64 a cookie is made called chat_64. I am using this jQuery cookie documentation: https://github.com/carhartl/jquery-cookie

I was thinking that it would be done by putting them into an array, and then using opening a chat box for each cookie.

I have come to ask for suggestions on how this could be done?

Was it helpful?

Solution

Don't store that kind of information in a cookie, use sessions in your server. It's a big risk for privacy. Store session data or use a database, with a call to a php(for example) script that fetches the current chats from a database, an additional feature is that if the user logs off and then logs in again, the chats could stay the same. the table could be something like this:

chat_id | user_id | chatting_with_id | timestamp

When the user closes the chat window you might just set a time limit for the user to reopen the window and if he/she didn't, send a delete request for that row.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top