0

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.

Maraj Hussain
  • 1,580
  • 10
  • 26

2 Answers2

2

Twilio developer evangelist here.

When you list the channels a user has joined, you get returned a list of ChannelDescriptors. At this stage, you can query each ChannelDescriptor for the number of unread messages using the getUnconsumedMessagesCount method.

ChannelDescriptors 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.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • I have used ChannelDescriptor to get channel and then call getUnconsumedMessagesCount but still get 0 count in block result in iOS SDK – Ravi Raja Jangid Jul 31 '18 at 05:15
  • If you believe this is a bug, then I recommend you get in touch with [Twilio support](https://www.twilio.com/help/contact) and give them as much detail about this issue that you can. – philnash Jul 31 '18 at 06:22
  • Hi, any updates on this as its now outdated. There is this a method under Channel but always returns null. – KasparTr Aug 04 '20 at 21:36
  • Hi @KasparTr, the method returns `void` because you need to pass a `CallbackListener` as an argument to `getUnconsumedMessagesCount`. The callback will be called with the result of the method. Check out the latest docs here: http://media.twiliocdn.com/sdk/android/chat/releases/6.1.0/docs/classcom_1_1twilio_1_1chat_1_1Channel.html#aa38dbac393f68e4e2ae7de23e4f5ddb6. Also, there is a note: "if the last consumed index has not been yet set for current user as the member of this channel then unconsumed messages count is considered uninitialized. In this case null is returned." – philnash Aug 05 '20 at 01:01
  • @philnash Thanks for this reference! Will review but im really after for a much simpler method- just to decide if user has new messages or not (no count). Kindly see full question: https://stackoverflow.com/questions/63255527/what-is-the-simples-way-to-see-if-twilio-chat-member-user-client-has-unread-mess. – KasparTr Aug 06 '20 at 18:07
0

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.

  • HOw do you set the Consumption Horizon with the Swift API? I cannot find a way to do this and as a result when I ask for the number of unread messages it returns 0 – Ben Smith Aug 19 '18 at 17:43