Query if a site member is logged in

Hi,

I have created a internal chat application on my site and I allow members to talk one on one. So lets say member A is talking to member B. I want it so that if member A logs off when member B sends a message I can send them an email saying they have a new message.

Ideally if i could use something like this…

let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn; 

But that only works for the current user. If there was something more like this…

let user = wixUsers.User(user's_ID or owner);
let isLoggedIn = user.loggedIn;

Any insights or tips would be very appreciated.

look at David Seroy’s replies in this previous forum thread.
https://www.wix.com/corvid/forum/community-discussion/user-chat-messenger

Hi GiveMeAWhisky

Thanks for sharing. I have seen that thread. Very useful for creating the chat messenger.
I have already created the chat messenger.

I wanted to add on to it.

So for example even in this chat. You sent me this message 40 minutes ago. I was actually away from my screen. But i got an email from wix saying someone had commented on my post.

Thats what i want to do. When two people are using the chat but one person is away from their computer or logged out or not in front of their screen etc. I want to send them an email saying they have a message

Just set up a Wix Automation
https://support.wix.com/en/ascend-by-wix/wix-automations

Or do a triggered email.
https://support.wix.com/en/article/about-triggered-emails

Took a quick look at both those links. Looks promising. I will give them a try. Fingers crossed. Thank you

Took a closer look at both. Not sure I can use either. But i could be missing something.
My problem isn’t how to send and email.

My problem, is that I only want to send a single email when one person in the chat is offline. Just to let them know they got a message. Once they log back in or for future messages they get while offline, they don’t get another email.

I am not sure how to find out if another member is logged in or not.

Well, if you use David’s code and look on page 2 of that previous forum post linked above, then you are already referencing the _id of the user, so you can just get their email then and then simply use either:
Email User
https://www.wix.com/corvid/reference/wix-users-backend.html#emailUser
Email Contact
https://www.wix.com/corvid/reference/wix-crm.html#emailContact

To check if user is logged in or not.
https://www.wix.com/corvid/reference/wix-users.User.html#loggedIn