Reputation: 547
I have 1 user and a list of friends of this user in Firestore. How to show this user's friends as online status? If offline will not show
User:{
ListFriend:[UserA,UserB,...]
}
Upvotes: 0
Views: 1605
Reputation: 598901
Firestore does not have any built-in capability to track the user's online status. The closest you can get with purely Firestore is to have each user regularly write a timestamp to the database (which they can only do when they're online), and then have each client determine from that who it considers currently online.
Firebase's Realtime Database does have the ability to track when a user disconnects from the server, and perform a (server-side) action in response to that. You can see more about this in its documentation on detecting connection state and its sample presence app.
There is also documentation on how to combine Firebase's Realtime Database presence system with Firestore. For more on this, see Build presence in Cloud Firestore. Finally an alpha version of an Extension that encapsulates the same functionality was announced in October 2020, so you might want to check that out in the blog post.
Upvotes: 2