Setup sending chats and users to the client

This commit is contained in:
jsrobson10 2019-04-12 17:16:38 +10:00
parent 31ab993699
commit 87207647e0
1 changed files with 18 additions and 6 deletions

24
main.js
View File

@ -437,23 +437,35 @@ var server = net.createServer(function(socket)
var chat_keys = Object.keys(chats);
var chats_client = {};
// Loop over them
// Get a list of user keys
var user_keys = Object.keys(users);
var users_client = {};
// Loop over the chats
for(var i=0;i<chat_keys.length;i++)
{
// Register the key to the temporary varible
chats_client[chat_keys[i]] = new Object();
// Set the chat name
// Set the chat data
chats_client[chat_keys[i]].name = chats[chat_keys[i]].name;
chats_client[chat_keys[i]].messages = chat[chat_keys[i]].messages;
}
console.log("Sending list of chats");
// Loop over the users
for(var i=0;i<user_keys.length;i++)
{
// Register the key to the temporary varible
users_client[user_keys[i]] = new Object();
}
// Send the list of chats
console.log("Sending server data");
// Send the server data
socket_write(sock, {
mode: "chat_list",
chats: chats_client
mode: "login",
chats: chats_client,
users: users_client
});
}