I am using flutter, firebase cloud messaging, firebase cloud function and firestore. I am looking for a way to send push notifications to my app on data changed in firestore.
Problem 1: The app also allows users to customize their preference settings. For example, user can subscribe to each Item and any of its fields like price, expiration date, etc, thus they will only receive notifications from those subscribed fields from that Item only.
Problem 2: The app also allow users to customize their time-to-receive settings freely (just like how Slack builds). For example, user might want to receive notification only before midnight or after 10am, and another one only want to receive them at 7am-8am Monday (for example).
Current setup: I trigger cloud function everytime there's a change in any Items, and this will send notifications to fcm topics that follows this pattern "item_${itemId}_${changedField}". This works fine for Problem 1, but when it comes to problem 2, things get harder, since I can't create a new topic for each hour and day, because there will be too many topics for client to subscribe and unsubscribe for just a single Item and for cloud function to send notifications to.
Please any suggestions, thanks.
In a scenario such as this (and honestly: many others) consider separating the delivery of the message from the display of the message. You can do this by using a message that only contains a data
node (so no notification
node). For such messages, it is always up to your code to handle the data.
So:
data
only message to the topic.