Change user status when online with websockets (ratChet php)

0

I'm doing a chat using websockets with ratChet, and I have a question regarding the status of the user.

I made the page load a list of all the contacts the user has, and when the server receives the connection from a user I do a search for that list of contacts by the user that just logged in doing the following:

Onmessage event:

conn.onmessage = function (event) {
    //console.log(event);

    var package = JSON.parse(event.data);

    if (package.type == 'message') {
    dialog_output(package);
    } else if (package.type == 'userlist') {
    users_output(package.users);
    }
};

Function that changes status color:

    function users_output(users) {

    for (var i in users) {

    if (users.hasOwnProperty(i)) {
        var user = users[i];

        user_list.find('li').each(function(i){
            if($(this).attr("data-id") == user.id){
                $(this).css("color", "rgb(50, 250, 0)");
            }else{
                $(this).css("color", "#000");
            }
        });

    }
    }
}

It's working like this, but I wanted to know if it's the right thing to do? It has come to my mind that regardless of whether the new user who just logged in is logged in or not, he will still compare it to the contact list.

    
asked by anonymous 06.01.2018 / 13:08

0 answers