使用 GetStream API,如果通知被分组,我会得到不正确的未见和未读计数

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

我正在按照以下方式在服务器端创建通知

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();

在客户端,当发送新通知时,我正在调用

  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);
                });

问题是,我的通知被分组,如果有多个新通知(例如 3 个),属性 unseen/unread 计数仍然是 1 而不是 3。 所以我找到的唯一解决方法是确保每个通知在唯一组中都是唯一的,所以我使动词唯一...

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

它似乎完成了工作,通知没有分组,但我觉得这是一个 hack,所以 我的问题是,如果我的通知已分组,我如何获得 unseen/unread 的正确编号?

未看到和未读计数基于 unread/unseen 的组数,而不是基于单个活动。通知源支持开箱即用的最常见 use-case:Facebook 的通知源。

在这种情况下,您想要的是按 ID ({{ id }}) 聚合活动。当你这样做时,每个组将始终有 1 个 activity,并且每个插入都会将 unseen/unread 增加一个。

这与您所做的类似,只是您不必破解动词的唯一性。为此,您需要通过 Stream 的仪表板配置您的通知提要组,并将聚合格式更改为 {{ id }}.