1

I'm trying to display all user's conversations sorted by last message creation date and I'm a little bit confused.

I see getSubscribedConversation method in docs (https://media.twiliocdn.com/sdk/js/conversations/releases/1.1.0/docs/Client.html#getSubscribedConversations__anchor) but it says nothing about page size and sorting. It returns paginator so I assume it doesn't return all conversations at once.

On the other hand I see some examples in twilio github projects where conversations are added to the list only by listening for conversationAdded event (which indeed fires even for previously created conversations) but it doesn't seem like a clean solution - if user belongs to 50 conversation then I should handle every single event and rerender the list 50 times?

To sum up, I have following questions:

  1. Does getSubscribedConversation returns all user's conversations at once?
  2. If no, then what is default page size and is it possible to change it (together with sorting)
  3. If getSubscribedConversation return paginator indeed - wouldn't it break if I add conversation from conversationAdded event in the meantime?
emzet93
  • 13
  • 2

1 Answers1

1

I can't answer all your questions but I can give some insight on a couple -

From what I can tell, getSubscribedConversations returns 50 Conversations. I have not found a way to change that limit or sort it (I'm not entirely sure in what order Twilio returns them even).

For a project I'm working on we need Conversations sorted in order of recent message. The way I'm currently dealing with it is by storing the most recent message on an attribute on the Conversation. I also initialize the app by loading all the conversations with a recursive function.

Hope that sheds some light for you.

  • 1
    Thanks for your answer @Rene. I had the same case in my project and solved it in exactly same way - fetching all pages in recursion and sort it locally.I also chat with Twilio support and they confirmed that getSubscribedConversations method returns 50 items and there is no way to sort it or change the order. – emzet93 May 15 '21 at 20:08
  • Oh nice, @emzet93! Glad to know I'm not alone in that approach! I initially call `getSubscribedConversations` to get the initial 50 then do my recursion in the Paginator calls. Curious if that's similar for you. – babycourageous May 16 '21 at 22:03
  • It seems like a very inefficient way achieve this though. I can imagine this getting very out of hand when you're dealing with thousands of conversations. There has to be a better way. – Saumil Shah Aug 22 '22 at 13:19