问题
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