I'm trying to get the number of messages unread for a specific member in a specific channel. To do this I was hoping to use channel.getUnconsumedMessagesCount() as defined in the documentation.
myChannel.join()
.then(function(c) {
console.log('Joined channel ' + c.sid);
return myChannel.getUnconsumedMessagesCount();
})
.then(m => {
console.log('current count unread: ' + m);
});
The unread count always return 0. To test, I do the following:
Initially I called .getUnconsumedMessagesCount() without doing join() first, I thought this could be the issue, but even with join still nothing.
before you can get UnconsumedMessagesCount you need manually set last read message (Send a Consumption Report)
something like this (JS)
channel.getMessages(1).then(function (messages) {
var last_message_index = messages.items[0].index;
channel.updateLastConsumedMessageIndex(last_message_index);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With