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 and want to have the full list channel every time. Please let me know if I’m missing something.

Hi @pucca_garu,

You should be creating a new query every time you need to re-query the entire list. next() is used for pagination and thus tracks the original query.

Could you elaborate more on how to re-declare the query so that it will be new? the whole thing below will get called when my app state is updated including the first line. Should sb.GroupChannel.createMyGroupChannelListQuery() returns the new query? How to reset the query?

// 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 => {
            ...
        });

        ...
    });
}

For me, I create a wrapper function so that I can generate a new listQuery any time that I need to query again.

For example:

export const createMyGroupChannelListQuery = () =>
  new Promise((resolve) => {
    const sb = SendBird.getInstance();
    const listQuery = sb.GroupChannel.createMyGroupChannelListQuery();
    listQuery.order = 'latest_last_message';
    listQuery.limit = 10;
    listQuery.includeEmpty = true;
    resolve(listQuery);
  });

Then anytime I would need to get a new list of channels, I simply call params = createMyGroupChannelListQuery() and then query off that. So each time I’m returning a new instance of the listQuery.