Notifications 使用GetStream API,如果将通知分组,我会得到不正确的未看到和未读计数
我正在服务器端按照以下方式创建通知Notifications 使用GetStream API,如果将通知分组,我会得到不正确的未看到和未读计数,notifications,getstream-io,Notifications,Getstream Io,我正在服务器端按照以下方式创建通知 String target = "oxyn"+notif.getTarget().getOid(); log.info("creating notification for target user {}",target); NotificationFeed notifications= client.notificationFeed("notification",target); notifications.a
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),未看到/未读的属性计数仍然是1而不是3。
所以我找到的唯一解决方法是确保每个通知在唯一组中是唯一的,所以我使动词唯一
.verb("receive"++notif.getOid())
它似乎完成了任务,通知没有分组,但我觉得这是一种黑客行为,所以
我的问题是,如果我的通知被分组,如何获得正确的未读/未读数量?未读和未读计数基于未读/未读组的数量,而不是单个活动。通知提要支持最常见的开箱即用的用例:Facebook的通知提要 在本例中,您希望通过活动的id(
{{id}}
)聚合活动。当您这样做时,每个组将始终有1个活动,并且每次插入将使未看到/未读的活动增加1个
这与你正在做的事情相似,只是你不需要修改动词的唯一性。为此,您需要通过Stream的仪表板配置通知提要组,并将聚合格式更改为{{id}