Reputation: 25
I am using pusher chatkit for my chatting app. Currently my app is able to chat with each individual, but my problem is if I (user1) am chatting with user2 and in between user3 text me from his account then how could I show badges that user3 sent me 4 messages.
Is there any solution or sample code to achieve this feature.
Upvotes: 1
Views: 197
Reputation: 4091
You can get the unread count for messages using the unreadCount room property. There is a tutorial which shows how to get the unread count and manage the cursors. The JS docs for Chatkit includes some code snippets for managing the unread count: https://pusher.com/docs/chatkit/reference/javascript.
For example, the following will log the unread count when a user joins a room, and will set the user's cursor each time a message is received.
currentUser.subscribeToRoomMultipart({
roomId: this.currentRoom,
messageLimit: 100,
hooks: {
//Message is received
onMessage: message => {
this.lastMessage = message.id;
//set cursor
currentUser.setReadCursor({
roomId: this.currentRoom,
position: this.lastMessage
})
.then(() => {
console.log(`Set cursor to message ${this.lastMessage}`)
})
.catch(err => {
console.log(`Error setting cursor: ${err}`)
})
}
},
}).then(room => {
//log unread count
console.log(`Unread count: ${room.unreadCount}`)
});
Upvotes: 1