Lindsey
Lindsey

Reputation: 11

Retrieving all active users from Firebase

I'm currently working on a Flutter app and I need to display all active users on one screen with their username, picture and age. How can I retrieve only the active users from Firebase and display then on the app with their respective information.

Upvotes: 0

Views: 261

Answers (1)

Huthaifa Muayyad
Huthaifa Muayyad

Reputation: 12353

First, you have to store a property in every user document, to show that they are active. You can do this by setting up a stream to Firebase function that updates the user document every two minutes for example.

When you want to know the users online, you can run a query, where the difference between current timestamp and the saved timestamp in firebase is not more than 120 second for example. This will return the users active in the last two minutes. You can change it to one minute or ten seconds or as much as you want.

Upvotes: 1

Related Questions