pucca garu
pucca garu

Reputation: 107

sendbird createMyGroupChannelListQuery return empty when recall

I'm using SendBird Javascript SDK createMyGroupChannelListQuery() and the instance's next() method to retrieve the list of group channels. However, it will return the list only one time after initialized the instance, the next time it gets called, it result is always an empty array. Since I need to fetch the channels multiple times I need to have the full list of channels always. Please let me know if you have experienced this.

// Retrieve a list of channels
var listQuery = sb.GroupChannel.createMyGroupChannelListQuery();
listQuery.includeEmpty = true;
listQuery.order = 'latest_last_message'; 
listQuery.limit = 100;   // The value of pagination limit could be set up to 100.

if (listQuery.hasNext) {
    listQuery.next(function(groupChannels, error) {
        if (error) {
            // Handle error.
        }

        // A list of group channels is successfully retrieved.
        groupChannels.forEach(channel => {
            ...
        });

        ...
    });
}

Upvotes: 0

Views: 528

Answers (2)

Walter Rodriguez
Walter Rodriguez

Reputation: 11

I have a sandbox for you to try:

https://codesandbox.io/s/javascript-has-next-problem-fducb?file=/src/index.js

Change APP_ID and USER_ID

Check the console, it should appear "First time" and the list of channels and then "Second time" and again the list of channels.

Upvotes: 0

Walter Rodriguez
Walter Rodriguez

Reputation: 11

To call it again and get the result, just call:

listQuery.hasNext = true;

Upvotes: 1

Related Questions