/ SDKs / Unity
SDKs
Chat SDKs Unity v4
Chat SDKs Unity
Chat SDKs
Unity
Version 4

Filter group channels by user IDs

Copy link

To filter group channels by user IDs, use SbGroupChannelListQuery's UserIdsExactFilter or UserIdsIncludeFilter. Let's assume the ID of the current user is Harry and the user is a member of three group channels.

  • Channel A: Harry and Jay.
  • Channel B: Harry, John, and Jin.
  • Channel C: Harry, John, Jin, and Jay.

A UserIdsExactFilter filter returns a list of the current user's group channels containing exactly the queried user IDs. In case you specify only one user ID in the filter, the filter returns a list of the current user's one or more distinct 1-to-1 group channels with the specified user.

SbGroupChannelListQueryParams queryParams = new SbGroupChannelListQueryParams();
queryParams.UserIdsExactFilter = new List<string> { "Jay" };

SbGroupChannelListQuery query = SendbirdChat.GroupChannel.CreateMyGroupChannelListQuery(queryParams);
query.LoadNextPage((inChannels, inError) =>
{
    if (inError != null)
        return; //Handle error.
});

A UserIdsIncludeFilter filter returns a list of the current user's group channels including the queried user IDs partially or exactly. Depending on the value of the SbGroupChannelListQueryType parameter, different results can be returned.

SbGroupChannelListQueryParams queryParams = new SbGroupChannelListQueryParams();
queryParams.SetUserIdsIncludeFilter(new List { "John", "Jay", "Jin" }, SbGroupChannelListQueryType.And);

SbGroupChannelListQuery query = SendbirdChat.GroupChannel.CreateMyGroupChannelListQuery(queryParams);
query.LoadNextPage((inChannels, inError) =>
{
    if (inError != null)
        return; //Handle error.

    // Channels should include only { "John", "Jay", "Jin" } as a subset. 
    // Thus, if successful, only Channel C is returned.
});

queryParams = new SbGroupChannelListQueryParams();
queryParams.SetUserIdsIncludeFilter(new List<string> { "John", "Jay", "Jin" }, SbGroupChannelListQueryType.Or);

query = SendbirdChat.GroupChannel.CreateMyGroupChannelListQuery(queryParams);
query.LoadNextPage((inChannels, inError) =>
{
    if (inError != null)
        return; //Handle error.

    // Channels may include any of the items in { "John", "Jay", "Jin" }.
    // Thus, if successful, all Channel A,B, and C are returned.
});