Reputation: 1596
I am trying to get unread messages count for each channel of the user.
After referring Twilio Doc For getting unread count, I found that this is a very complex way to get the message for each channel if channel count is large.
My question is that it is the only way to get the unread message count in Twilio because one channel it is taking some time to be initialized. and return unread count.
Upvotes: 0
Views: 4738
Reputation: 1
https://www.twilio.com/docs/chat/consumption-horizon
This link can be helpful.
Note : Chat does not automatically set the Consumption Horizon. If you do not explicitly set this within your application, no Consumption Horizon will exist for a User within the Channel. Without a Consumption Horizon, your user's Consumption Horizon (read status) will not synchronize correctly across clients. If a user does not have a Consumption Horizon set on a channel, getting unconsumed messages will always return 0. If a member of a Channel has no consumption status, their last consumed index and timestamp will be null or 0 depending on the platform.
Upvotes: 0
Reputation: 73065
Twilio developer evangelist here.
When you list the channels a user has joined, you get returned a list of ChannelDescriptor
s. At this stage, you can query each ChannelDescriptor
for the number of unread messages using the getUnconsumedMessagesCount
method.
ChannelDescriptor
s don't update in real time though, so you will want to register to listen for incoming messages and update the counts yourself after that.
Hope that helps.
Upvotes: 2