Twilio - channel descriptor paginator order

笑着哭i 提交于 2020-02-07 01:31:36

问题


I want to retrieve the list of channels for a user containing unread messages. The best solution I have found so far (please correct me if I'm wrong) is using channel descriptors.

// Example for a single page
client.getUserChannelDescriptors().then(function(paginator) {

  for (var i = 0; i < paginator.items.length; i++) {
    var descriptor = paginator.items[i].descriptor;

    if (descriptor.unread_messages_count > 0) {
      console.log("Channel found, id: " + descriptor.uniqueName);
    }
  }
});

My question: is there a way to order in the paginator object so I could retrieve channels with unread messages first so I wouldn't have to go through the whole list of channels?


回答1:


Twilio developer evangelist here.

You can sort channels, but not with getUserChannelDescriptors. Instead, you need to make sure you've loaded all the subscribed channels and then you can sort them with getLocalChannels.

From the docs:

getLocalChannels( [sortingOptions])

Get array of Channels locally known to Client in provided sorting order. Locally known channels are the ones created and/or joined during client runtime and currently logged in User subscribed Channels. To ensure full list of subscribed Channels fetched - call the Client#getSubscribedChannels method and fetch all pages with help of Paginator#nextPage method.

The sorting options then allow you to sort by lastmessage.



来源:https://stackoverflow.com/questions/53344782/twilio-channel-descriptor-paginator-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!