Can I run a code on a random (not current) user browser?

I also have read your post, but did not understand this sentence here…

Is there a way to notify ‘To’ user, if he/she is logged in, once a message has been sent?

  1. Who exactly is logged-in?
  2. Notify who?

You want to notify the recipient, that a message is available for him?

Of course the real-time-API will be the right answer here, but are there also workarounds existing?

SCENARIO:

  1. User-A creates a messsage and sends it to the → Messages-Collection
  2. Of course the message is saved with a user-ID → sending-user.
  3. But surely you also will have generated a DB-Field called recipientID, or similar, to make sure the right person will get the message.
  4. Let’s call the two ID’s → senderID / receipt ID

Soo, User-A sends the message including the two-IDs and the data is saved inside your Messages-Collection.

How to notify now the → recipient?

You can generate on the MASTER-PAGE an ----> INTERVAL-FUNCTION , which will check for example every x-seconds/minutes for changements inside your Messages-DB .

If a changement is registered → you grab the last changed data (regardind the most actual changing-date).

Now you are able to find the last UPDATED-DATA → getting its both IDS and continuing what ever you want to do with those two IDs .

But what’s with the ALERT-MESSAGE ?

What about a → Poping-Up-Lightbox → which will appear emmedialtely, when a changement inside DB has been found?

This description, shows you just a workaround, of how to set-up your wished functionality the MANUAL-way.

But perhaps you better should take a look onto J.D.'s provided → Real-Time-API!