Support Topics Documentation Slack YouTube Blog

Getting currently active and inactive users

How do I get the currently active users on backendless. I don’t mean logged in users here coz I enabled stay logged in for each users login. I need to get the currently active users and those inactive. Is this possible. If yes please help.

What’s a definition of an “active” vs. “inactive” user?

OK not to cause any confusion, and to be understood I mean how to get users that are online and offline.

Coz I will need to notify any current user all his followers that are online.

Hope am been understood @mark-piller

How would our backend know that your user is offline?

Yes and how to retrieve the response either online or offline.

You can make a session just like the login sessions to check for any api call and if there isn’t an api call for a certain period of time then the user is either busy or offline. Else the user is still online.

You can make a session just like the login sessions to check for any api call and if there isn’t an api call for a certain period of time then the user is either busy or offline. Else the user is still online. That my idea.

This is often handled through a presence system; when a user state changes (offline to online or away to present or active to inactive for example) the apps sets flag in the database for that user in the user table; online = true, and when they log off online = false. That way, they can stay connected but have an indicator as to their state.

Your app can watch for that change in the users table and update your app/UI accordingly as other users go online and offline.

The trouble with this design pattern is; what happens in the case of a disconnect or the user force-quits the app. In those cases the app cannot change that flag.

Firebase has a very intuitive way of handling that situation through a onDisconnect function that lives on the server. The server monitors the connection and if it’s lost will fire a pre-defined event. In that case onDisconnect could set the online flag to false for the user that disconnected.

I realize that’s not much help but it’s a very usable and reliable function that we implement throughout our Firebase backed projects.

Does such a function or capability exist in Backendless?

Backendless provides support for that functionality through real-time event handlers.
To accomplish the logic described above, you can add business logic in Java, JS or Codeless to handle the following events:

clientConnected:
In this event handler you would mark your user as online
Event Handlers - BL - DemoApp - Backendless 2020-03-07 08-49-58
clientDisconnected:
In here your cloud code would mark the user as offline:
Event Handlers - BL - DemoApp - Backendless 2020-03-07 08-50-49

The code to change the state of the user is trivial - it is a simple update of a single property.

Hope this helps.

Mark