Select Current Active Users | Check if Session User is Active Or Not?

Hi Community,

I have been tried to select the current active - online - sessions of users, by tracking the chat code, but I can not summarize the code.
also, I have been tried to get check if a specific user is online or not. also without any benefit.

Does anyone know the answers to the last two questions?
Thank you in advance.