Subscribing to realtime changes for a notification feed
benmgreene opened this issue · 9 comments
I have a notification feed that I'm attempting to subscribe to so that I can alter the unseen notifications count. Getting the count on the initial call works fine, but the callback passed to subscribe
is not being called.
Meteor.call('userNotificationsFeedToken', function(err, token) {
var notification_feed;
if (err) {
return console.error(err);
} else {
notification_feed = Stream.feedManager.getFeed('user_notifications', User.current()._id, token);
notification_feed.get({
limit: 1
}).then(function(data) {
return unseen_notifications_count.set(data.unseen);
});
return notification_feed.subscribe(function(data) {
return unseen_notifications_count.set(data.unseen);
});
}
});
Thanks for your help.
Why not just subscribe to the publication i.e.:
var subscription = Meteor.subscribe('Stream.feeds.notification');
if (subscription.ready()) {
var enriched = Stream.feeds.notification.find().fetch();
}
This will also give you live updates on the notification feeds, without worrying about generating tokens for client side. Because you are using a non-standard feed group name you would have to configure this feed group in your settings.json:
{
// ....
notificationFeed: 'user_notification'
}
This is the default configuration: https://github.com/GetStream/stream-node/blob/master/src/config.default.js
I am actually using that approach elsewhere (and it works very well), but for this I'm just trying to get a count of the unseen and unread notifications. What is your recommended way of doing that in Meteor?
Thanks much.
I get it. Yes that use case isn't covered by the current publication made by this integration library, it is actually a good idea to add it (since we are already listening for realtime changes on the server with this meteor library). Otherwise the code you provided above should work. I will have to investigate why this code is not working. If you want feel free to create a PR to add the functionality to track unread notifications via integration library. Otherwise I will have to see when I can find time to add this.
@benmgreene do you have realtime notification enabled on this notification feed (you can check this in the feed group configuration on the getstream.io dashboard).
Yep.
So I've been doing some digging. Some actions do trigger the callback, and others don't. I haven't finished testing, but so far I've noticed that:
Stream.feedManager.getFeed('...', user_id).get(mark_seen: true)
does NOT trigger the callbackStream.feedManager.getFeed('...', user_id).get(mark_read: [a_id])
DOES trigger the callback
Working on some more tests, will update.
Another:
Stream.feedManager.getFeed('...', id).addActivity( activity )
DOES trigger the callback
You only get Faye updates for unread
and unseen
when you supply a list of id's to mark. When you supply a boolean to either one of these it will not trigger a realtime update.
Ok -- what's the reasoning for that?
Thanks for the new getNotificationFeedStats
method! It's working pretty well. I did find a bug (which I have fixed) -- see #6