In my Firestore I have a collection GROUPS in which their are multiple groups. Whenever a new message is added to group I want to send notification to members of that group only.
CodePudding user response:
There are various ways to achieve this,
subscribe user to group as a topic here i'm assuming your structure is
-groups
-group1 -member1 -member2 -group1 -member1
_firebaseMessaging.subscribeToTopic("groups/group1");
- fetch each user token and send a notification . read more here
CodePudding user response:
You should use FCM "firebse Cloud messaging" but from a server side i suggest using Node-js "easy to install and use"
You have 2 methods to achieve this 1 - using Firebase cloud functions : it has a triggers that can be fired whenever data has been written , removed or updated so you will use create trigger to send the notifications but unfortunately cloud function is not free any more you should be on blaze "paid subscription"
any way you can follow the documentation from here https://firebase.google.com/docs/functions/get-started https://firebase.google.com/docs/functions/firestore-events
2- using snapshot listener to listing on the added data on this collection and then send the notifications its free if you upload the app.js to a free host
https://firebase.google.com/docs/firestore/query-data/listen#node.js_1
Sending notifications logic : You can iterate on the users you have to send the notifications to Or just assign for each a Topic so that when they can subscribe to it If still not clear i'll post codes