Reputation: 1
Twilio chat is returning getUnconsumedMessagesCount as null for all channel even channel has unread messages.
Any twilio expert here
The consumption horizon is updated with "setAllMessagesConsumed" and "updateLastConsumedMessageIndex" method still no luck.
This is working earlier in my application and the functionality is broken suddenly.
Below is the code
const clientChannel = await this.chatService.getChannel( channel_sid );
console.log('clientchamnel: ', clientChannel.status);
if (clientChannel.status !== 'joined') {
await clientChannel.join();
}
this.lastMessage = { body: '' };
// get channels last message
clientChannel.getMessages().then(messages => {
if (messages && messages.items && messages.items.length > 0) {
this.lastMessage = messages.items[messages.items.length - 1];
}
});
// get last unconsumedMessage so we can color the item if its read or not
clientChannel.getMessagesCount().then(totalCount => {
console.log('total count:=' + totalCount);
clientChannel.getUnconsumedMessagesCount().then(unconsumedCount => {
console.log('unread count:=' + unconsumedCount);
if (unconsumedCount != null && unconsumedCount > 0) {
this.channel.unread = true;
} else if (unconsumedCount == null && totalCount) {
this.channel.unread = true;
}
});
});
Upvotes: 0
Views: 1048
Reputation: 101
getUnconsumedMessagesCount will return null if the user has never called updateLastConsumedMessageIndex. I tend to rely on the getMessagesCount in that case (as a workaround), to get the number of messages unread.
Upvotes: 2
Reputation: 641
I made it work calling setAllMessagesConsumed
after user joins channel on the backend side, using the webhook feature.
Upvotes: 0