Does some package or pattern for push notifications for users in Meteor already exist? So I would like to have some way for server to send a notification to the user which is then displayed to the user. Is there something already there? Or should I just create a collection of notifications and get client to subscribe to it, displaying anything which is there as it gets pushed?
At the moment as far as I know theres no way to subscribe to something thats not a collection so to push custom data like a push notification down to the user you would need to use a notification collection.
On your client side you can have an observer that listens for new notifications
Notifications.find().observe({
added:function(document): {
//Push notify your client
Notifications.remove(document._id); //Remove when viewed
}
});
A really nice library to display these on the client is : http://github.hubspot.com/messenger/ you could have it pop up as soon as you insert something into the notifications collection
Related
In this simple scenario, why would someone choose to pay for a realtime service like Firestore for delivering latest updates, when a system based on Push Notifications can work as good?
If the user is not in the app, you can refresh the page as soon as the user taps the notification or opens the app. When the app is open you can refresh when a data notification is received.
What am I missing?
Why should anyone use something like Firestore when Push Notifications seems to be enough?
I need to listen for update on the client side whenever something in the Firestore database changes.
I need some clarification about this topic:
Let's say that we want to notify the user whenever a new document is created in a collection:
We have 2 cases:
when the user is on the app
when the user is out of the app
for the second point I can create a cloud function firestore trigger that notifies the user through the push notification service
But on the first point I don't know which is the best approach.
(maybe setting up a snapshotListener? but how can I do that on the global scope of the app? Is it the right approach?)
Should you implement a FCM notification for the second scenario, the notification will be fired to your app no matter if it is on background or foreground, so you can use this approach for both situations actually.
You can use this solution to not fire a notification (on the frontend) and in case you don't want to fire that if the app is in foreground you can just keep the completionHandler() blank and that's it.
I am building an app contains chat but i couldn't figure out somethings.
Notifications: I can send notifications to devices but they appear everytime (app in on screen or not) but i want to send "chat" notification only the chat page not open. I think i need to send data notifications instead of normal notifications.
Storing chats: I can't pull all the chats eveytime user wants to see messages. I need to store them and show only the new messages. How can i seperate them? Device has to say i have messages until this timestamp give me newer ones.
I am using firebase and gifted chat. I can give you any version codes if you want.
Let say user A subscribe event source push notification at device A at 10am and subscribe event source push at device B at 11am without unsubscribe. If my backend send the push message, both devices will receive the push message? I actually just want to send the message to the latest devices user have subscribed. Is there anyway to do this?
Like Idan suggested you can inspect push subscriptions in the database . Susbscriptions have an associated timestamp entry . With this you can determine the latest one for the user.
You can then use WL.Server.notifyDevice(userSubscription, device, options) or WL.Server.notifyDeviceSubscription(deviceSubscription, notificationOptions) to target a specific device.
If the user subscribed to two different event sources then yes, the user will receive notifications in both event sources...
There is no built-in mechanism that will prevent "duplicate" subscriptions (of the same user), so perhaps you could implement some sort of a cron job on your server to inspect the subscriptions table in the database and check that there are no duplicate subscriptions. If a duplicate subscription is found, delete the older one.
I want to create an application which have 2 modes: non-logged-in and logged-in (having username).
I want to send push notifications to devices in both modes. The non-logged-in devices should receive notifications such as general announcements, new events, etc. The logged-in mode devices will also receive same notifications and few more.
Now what I want to do is to subscribe the device to receive notifications for non-logged-in mode then once the user logs in to his account from that device I want to unsubscribe the previous non-logged-in notifications.
I've read the answer to this question : Worklight: Push notification without User ID I think that I can play with onUserSubscribe callback when registering the user and unsubscribe the userId of the persistent cookie.
Is this a good idea ? Is there another suggestion ?
My thinking is that you could register an app to 2 event sources.
The first event source will handle the general notifications that an app should receive, whether a user is logged-in or not.
The second event source will handle the notifications for logged-in users.
When the app launches, subscribe to the first event source.
When the user decides to log-in, subscribe to the second event.
You should allow the user to unsubscribe from both if s/he so chooses, as well.
Additional information:
IBM Worklight 6.1 Information Center: search for "push notifications"
Push Notifications training module
So what you're trying to achieve is push notifications broadcast (send to all users). This is something that you'll be able to do with upcoming Worklight 6.2 release. You will not have to subscribe users according to username, but will be able to specify tags during subscription. And after that you'll be able to send push notifications according to this tags.