简体   繁体   中英

Twilio chat - unread messages count

I'm looking for an efficient way to get and update count of unread messages in twilio chat. I've reviewed related Q&A here (like this ), and the anser was about looping through the Channel's array and Message Consumption Horizon. Is it the one way to solve it? It's not a cheap approach from the point of view of perfomance.

The second question is about ability to update this count on the fly - so, is there a way to create a notification for user with event handler for incomming messages (not push notifications) to update counter of unread messages in real time?

thanks in advance

here is the way I've used to update the unread count real-time.

Refer Channel/Conversation: For twilio-chat consider channel & for twilio-conversation consider conversation .

Listen to the 'messageAdded' event of ConversationClient. So whenever a new message is added you can check below:

  1. If you have any conversation in focus: match conversation SID & reset the unread count to the newly added message's index.
  2. If there isn't any conversation in focus or conversation SID does not match - then find out the conversation with the message's conversation SID & increment its unread message count.

Hope this is helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM