When triggered, my cloud function retrieves all the users from Firestore and sends them a Push Notification with their FCM token. My question is, how can I detect which FCM tokens are no longer active (i.e. which users have deleted the app) and remove them from the database? This is so I don't waste run time and send a million push notifications when only 1000 can receive it.
Right now, I store a Timestamp in Firestore every time the users opens the app, and if they don't open the app for 30 days, they are removed from the database. This is not a great solution as we may be deleting perfectly good users who just haven't opened the app in a while. And we will also be keeping users who deleted the app 5 minutes later.
I looked into seeing if we can detect when a user deletes an app, but that doesn't seem possible.
Any ideas on how I can accomplish this?
Is there any way to check if an FCM token is active?
Thanks.