Back

how to implement user status online/offline & last online time.

  • 0
  • Flutter
  • Databases
  • Realtime
  • Self Hosted
  • Users
kamal.panara
19 Jul, 2023, 19:49

I'm working my Flutter project in which i need to show user status, if user is online then it should show it to other user, and if it's offline then offline like any other chat apps as well as last online time.

TL;DR
The user wants to implement a feature for user status (online/offline) and last online time in a Flutter project. One suggestion is to use a heartbeat/pinging approach where the client sends a request to the server at regular intervals to indicate that it is still connected. If there is no response from the client after a certain interval, the server can assume that the user has disconnected. A cloud function cron job can be used to periodically check and update user presence, but it may have cost implications. Real-time connections like Firebase can handle unstable connections by waiting for a certain duration before marking the user as offline. The user should consider their requirements
kamal.panara
19 Jul, 2023, 20:01

what is minimum amount of interval duration is needed for updating presence doc to keep user status active?

Drake
19 Jul, 2023, 20:01

up to you, depending on your requirements. However, make sure not to hit the rate limit

kamal.panara
19 Jul, 2023, 20:02

like in firebase we do the same listen to event when it disconnects we make the user's status offline. and if user have unstable network then firebase wait for 60 seconds for user to connect back before making user offline.

kamal.panara
19 Jul, 2023, 20:04

so how realtime connection will handle the unstable connection?

Drake
19 Jul, 2023, 20:08

the suggestion was not to use realtime...

kamal.panara
19 Jul, 2023, 20:13

oh, I see, okay. so there is a chance of inaccuracy without some kind of real-time connection.

kamal.panara
19 Jul, 2023, 20:16

cloud function cron job to check and update user presence based on your suggestion without using realtime can work, but will it be more expensive? cron job for all users every minute can make it almost realtime user presence,

Drake
19 Jul, 2023, 20:54

No, function cron job was also not suggested

kamal.panara
21 Jul, 2023, 11:10

then what, please shower some light, i'm new here.

Drake
21 Jul, 2023, 14:32

You might want to πŸ‘πŸΌ this issue: https://github.com/appwrite/appwrite/issues/2418

For now, you can implement a heartbeat/pinging approach where the client sends a request every X interval to let the server know it's still around. After Y interval of no responses, the server would determine the user has left/disconnected

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more