/ SDKs / .NET
SDKs
Chat SDKs .NET v4
Chat SDKs .NET
Chat SDKs
.NET
Version 4

Group channel collection

Copy link

A SbGroupChannelCollection instance allows you to swiftly create a channel list view that remains up to date on all channel-related events. This page explains how to draw a view using the collection.


Create a collection

Copy link

First, create a SbGroupChannelListQuery instance. This determines which channel to include in the channel list and how to list channels in order.

Once the collection is created, you should call LoadMore().

// First, create a SbGroupChannelListQuery instance.
SbGroupChannelListQueryParams queryParams = new SbGroupChannelListQueryParams();
SbGroupChannelListQuery query = SendbirdChat.GroupChannel.CreateMyGroupChannelListQuery(queryParams);

// Second, create SbGroupChannelCollectionHandler instance.
SbGroupChannelCollectionHandler handler = new SbGroupChannelCollectionHandler
{
    OnChannelsAdded = (inContext, inChannels) => { /* Add new channels to your data source. */ },
    OnChannelsUpdated = (inContext, inChannels) => { /* Update the existing channels in your data source. */ },
    OnChannelsDeleted = (inContext, inChannelUrls) => { /* Delete the channels with the matching channelUrls from your data source. */ }
};

// Create a SbGroupChannelCollection instance.
SbGroupChannelCollectionCreateParams createParams = new SbGroupChannelCollectionCreateParams(query, handler);
SbGroupChannelCollection collection = SendbirdChat.GroupChannel.CreateGroupChannelCollection(createParams);

Pagination

Copy link

A SbGroupChannelCollection instance retrieves more channels to display in the view through the LoadMore() method.

Whenever a scroll reaches the bottom of the channel list view, the LoadMore() method is called and HasNext first checks if there are more channels to load. If so, LoadMore() fetches them.

The LoadMore() method should also be called after you've created a SbGroupChannelCollection instance.

// Check whether there are more channels to load before calling LoadMore().
if (collection.HasNext)
{
    collection.LoadMore((inChannels, inError) =>
    {
        if (inError != null)
        {
            return; //Handle error.
        }
    });
}

Channel events

Copy link

Use the GroupChannelCollectionHandler property in SbGroupChannelCollection constructor to determine how the client app reacts to channel-related events.

This is called whenever a new channel is created as a real-time event when the client app is back online.

The following table shows possible cases where each event handler can be called.

EventCalled when

OnChannelsAdded()

- A new group channel is created as a real-time event.
- New group channels are fetched through changelog sync.

OnChannelsUpdated()

- The channel information that is included in the user's current chat view is updated as a real-time event.
- Updated channel information is fetched through changelog sync.

OnChannelsDeleted()

- A group channel is deleted as a real-time event.
- A channel deletion event is fetched through changelog sync.


Dispose of the collection

Copy link

The Dispose() method should be called when you need to clear the current channel list view and unsubscribe channel events.

collection.Dispose()