# Exclude empty channels and pagination

**URL:** <https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521>\
**Category:** JavaScript\
**Tags:** group-channel, chatsdk\
**Created:** [December 9, 2021, 4:03am UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521 "2021-12-09T04:03:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hewong](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hewong/32/1817_2.png) [@hewong](https://community.sendbird.com/u/hewong)\
**Post date:** [December 9, 2021, 4:03am UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521/1 "2021-12-09T04:03:44Z")

</div>

I’m trying to fetch non-empty group channels by setting the `includeEmpty` option to `false`.

The channels that never had messages did successfully get excluded.

But I noticed if I go to a channel that has some messages and delete all the messages, making it “empty”, that channel will still be returned in the list.

Not sure if it is intended. And if it is, how does SendBird determine whether a channel is really “empty”?

* * *

Another question:  
What’s the better way to do pagination and why? `GroupChannelListQuery` or `GroupChannelCollection`?  
I’ve tried both and both works.

Thank you.

---

<div class="post-metadata">

**Author:** ![Alex\_Preston](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/alex_preston/32/167_2.png) [@Alex\_Preston](https://community.sendbird.com/u/Alex_Preston)\
**Post date:** [December 9, 2021, 7:08pm UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521/2 "2021-12-09T19:08:07Z")

</div>

Hey @hewong

I believe that the check is based on lastMessage. Let me run a check to see if you delete all messages if channel.lastMessage is also null or if that reference is missed when deleting.

I believe both will work. Collection is in reference to the SyncManager. You can read more about it [here](https://sendbird.com/docs/chat/v3/javascript/guides/local-caching#1-local-caching):

> Local caching operates on the `groupChannelCollection` and `messageCollection` classes, which are used to build a channel list and a chat view, respectively.

---

<div class="post-metadata">

**Author:** ![hewong](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hewong/32/1817_2.png) [@hewong](https://community.sendbird.com/u/hewong)\
**Post date:** [December 14, 2021, 7:48am UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521/3 "2021-12-14T07:48:52Z")

</div>

Hi, is there any updates regarding the investigation on empty channels?

I did a comparison between two empty channels (one was returned even when `includeEmpty` is set to `false`, and another one correctly gets excluded). Both channels has their `lastMessage`s set to `null`, I couldn’t really see what makes them behave differently…

Could you please help finding out the reason please?

---

<div class="post-metadata">

**Author:** ![hewong](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hewong/32/1817_2.png) [@hewong](https://community.sendbird.com/u/hewong)\
**Post date:** [December 16, 2021, 3:43am UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521/4 "2021-12-16T03:43:01Z")

</div>

Any updates on the empty channels please?

---

<div class="post-metadata">

**Author:** ![Alex\_Preston](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/alex_preston/32/167_2.png) [@Alex\_Preston](https://community.sendbird.com/u/Alex_Preston)\
**Post date:** [December 16, 2021, 10:55pm UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521/5 "2021-12-16T22:55:18Z")

</div>

Can you show me the query?

I am testing on the latest version and upon deleting last message in the channel to make it an empty channel it becomes channel.lastMessage = null.

---

<div class="post-metadata">

**Author:** ![hewong](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hewong/32/1817_2.png) [@hewong](https://community.sendbird.com/u/hewong)\
**Post date:** [December 17, 2021, 4:19am UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521/6 "2021-12-17T04:19:44Z")

</div>

Here’s the code I’m using currently

```auto
const order = this.sb.GroupChannelCollection.GroupChannelOrder.LATEST_LAST_MESSAGE;
const limit = 50;
const filter = new this.sb.GroupChannelFilter();
filter.includeEmpty = false;
filter.memberStateFilter = 'joined_only';

this.sb.GroupChannel.createGroupChannelCollection()
	.setOrder(order)
	.setLimit(limit)
	.setFilter(filter)
	.build();

```

I’ve also tried with the `GroupChannelListQuery`, doesn’t seems to make a difference

```auto
const listQuery = this.sb.GroupChannel.createMyGroupChannelListQuery();
listQuery.includeEmpty = false;
listQuery.memberStateFilter = 'joined_only';
listQuery.order = 'latest_last_message';
listQuery.limit = 50;

```

---

<div class="post-metadata">

**Author:** ![Alex\_Preston](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/alex_preston/32/167_2.png) [@Alex\_Preston](https://community.sendbird.com/u/Alex_Preston)\
**Post date:** [December 22, 2021, 12:52am UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521/7 "2021-12-22T00:52:43Z")

</div>

@hewong,

Have you tested this on our sample app? Your query does look correct.

As a follow up question. Do you even want to still use that channel that had all messages deleted? Or would you ideally like it to be gone? If so you could mark that channel as [hidden](https://sendbird.com/docs/chat/v3/android/guides/group-channel#2-hide-or-archive-a-channel-from-a-list-of-channels).

---

<div class="post-metadata">

**Author:** ![hewong](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hewong/32/1817_2.png) [@hewong](https://community.sendbird.com/u/hewong)\
**Post date:** [December 22, 2021, 1:24am UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521/8 "2021-12-22T01:24:45Z")

</div>

> [@hewong](#):
>
> how does SendBird determine whether a channel is really “empty”

Actually, I’d just like to _ **understand** _ if what I’m encountering (empty channels being returned after all messages deleted) is an intended behaviour or an unintended bug.

If it’s intended, meaning `includeEmpty` does not determine whether the channel is “empty” based on the `lastMessage` property, since it’s `null` in both cases (originally empty channel and manually made empty channel).

Really just wanted to understand whether it’s intended and how the `includeEmpty` param works. I know how I could handle it if it’s intended.

Thank you.

---

<div class="post-metadata">

**Author:** ![Alex\_Preston](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/alex_preston/32/167_2.png) [@Alex\_Preston](https://community.sendbird.com/u/Alex_Preston)\
**Post date:** [January 10, 2022, 10:16pm UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521/9 "2022-01-10T22:16:14Z")

</div>

I would say it doesnt seem like intended behavior. I would have to think there might be something wrong with the given channel. If you want to dm me the channel I can take a look further. Based on my tests with the sample app I was not able to reproduce the issue.

---

<div class="post-metadata">

**Author:** ![david](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/david/32/1901_2.png) [@david](https://community.sendbird.com/u/david)\
**Post date:** [October 13, 2022, 6:22pm UTC](https://community.sendbird.com/t/exclude-empty-channels-and-pagination/3521/10 "2022-10-13T18:22:31Z")

</div>

Are there any updates on this?  
I’m observing a similar issue.

1. Create a distinct channel with 1 other user
2. Send a message
3. Delete the message
4. [ListMyGroupChannels](https://sendbird.com/docs/chat/v3/platform-api/user/managing-joined-group-channels/list-group-channels#1-list-group-channels) with `show_empty` omitted (false default)
5. See the channel returned with no messages and no last\_message

The docs say “Empty channels are channels that have been created but contain no messages.” not “but _never_ contained messages” so I think this behavior is incorrect.
