Levancho
Levancho

Reputation: 149

Using GetStream API, I am getting incorrect unseen and unread counts if notifications are grouped

I am creating notification on server side following way

String target = "oxyn"+notif.getTarget().getOid();

        log.info("creating notification for target user {}",target);
        NotificationFeed notifications= client.notificationFeed("notification",target);
        notifications.addActivity(Activity.builder()
                .actor(notif.getTarget().getName())
                .verb("receive")
                .object(notif.getOid()+"")
                .foreignID(notif.getTarget().getName()+":"+notif.getOid())
                .extraField("message", notif.getMessage())
                .extraField("action", notif.getAction())
                .extraField("sender", notif.getSender().getOid())
                .extraField("oxyn", notif.getOxyn())
                .build()).join();

and on client side, when new notification is sent I am calling

  notification1 = client.feed('notification', ("oxyn"+me.oid));
            notification1.get({mark_seen:false,mark_read:false})
                .then(function(data) {
                  /* on success */

                  console.log("new : "+data.unseen);
                })
                .catch(function(reason) { /* on failure */
                  alert(reason);
                });

problem is, my notifications get grouped and if there is more than one new notification (for example 3) properties unseen/unread count still say 1 instead of 3. so the only workaround I found is to make sure each notification is unique within unique group so I make verb unique...

 .verb("receive"++notif.getOid())

it seems to do the job, notifications do not get grouped, but I feel like this is a hack, so my question is how do I get a correct number for unseen/unread if my notifications are grouped?

Upvotes: 2

Views: 559

Answers (1)

Tommaso Barbugli
Tommaso Barbugli

Reputation: 12031

Unseen and Unread counts are based on the amount of groups that are unread/unseen, not on the individual activities. Notification feeds support the most common use-case out of the box: Facebook's notification feed.

What you want in this case is to aggregated activities by their id ({{ id }}). When you do that every group will always have 1 activity and every insert will increase the unseen/unread by one.

This is similar to what you are doing except that you don't have to hack the uniqueness on the verb. To do this you need to configure your notification feed group via Stream's Dashboard and change the aggregation format into {{ id }}.

Upvotes: 2

Related Questions