[英]Objective C: How to check for unread messages (number to be displayed as badge)
[英]How to get the number of individual unread messages of PubNub?
我正在使用pubnub Services向我的应用添加聊天功能,但是我想知道是否有一种方法可以获取未读消息的数量。 我正在使用此链接-> https://www.pubnub.com/docs/swift/data-streams-publish-and-subscribe
这可以使用PubNub Functions完成。 函数是您自己的脚本,当一条或多个PubNub通道上发布消息时,这些脚本会在云中自动运行。
它具有键值存储区,具有increment
, decrement
和retrieve
功能。 可以非常直观地将其用于PubNub上的未读消息模式。
频道:房间。*
事件:发布前
// Access to Distributed Database
const db = require('kvstore');
export default (request) => {
// Conventionally build the Key ID based on the request parameters and channel name.
let counterId = request.channels[0] + '/' + request.params.uuid;
// Increment or Decrement the unread message counter
let method = request.message.read ? -1 : 1;
// Increment/Decrement and read the unread message counter
return db.incrCounter( counterId, method ).then(()=>{
return db.getCounter(counterId).then((counter) => {
request.message.unread = counter || 0;
return request.ok();
});
});
}
按照此官方指南,您可以将此新功能集成到现有应用中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.