Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
/
Channel
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Filter channels by user IDs

To filter group channels by user IDs, use userIdsExactFilter or userIdsIncludeFilter. Let's assume the ID of the current user is Emma and the user is a member of two group channels.

  • Channel A consists of Emma, Maya, and Brett.

  • Channel B consists of Emma, Maya, Brett, and Chelsea.

The userIdsExactFilter parameter 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.

const params: GroupChannelListQueryParams = {
  userIdsExactFilter: ['Maya', 'Brett'],
};
const query: GroupChannelListQuery = sb.groupChannel.createMyGroupChannelListQuery(params);

// Only channelA is returned in a result list through the groupChannels parameter of the callback function.
const channels: GroupChannel[] = await query.next();

On the other hand, the userIdsIncludeFilter parameter returns a list of the current user's group channels including the queried user IDs partially and exactly. Two different results can be returned according to the value of the queryType parameter.

const params: GroupChannelListQueryParams = {
  userIdsIncludeFilter: ['Maya', 'Brett', 'Chelsea'],
};
const query: GroupChannelListQuery = sb.groupChannel.createMyGroupChannelListQuery(params);

// Only channelB including {'Maya', 'Brett`, `Chelsea`} as a subset is returned in a result list.
const channels: GroupChannel[] = await query.next();
const params: GroupChannelListQueryParams = {
  userIdsIncludeFilter: ['Maya', 'Brett', 'Chelsea'],
  queryType: QueryType.OR,
};
const query: GroupChannelListQuery = sb.groupChannel.createMyGroupChannelListQuery(params);


/**
 * channelA and channelB include {'Maya'}, channelA and channelB include {'Brett'}, channelB includes {'Chelsea'}.
 * Both channelA and channelB are returned in a result list.
 */
const channels: GroupChannel[] = await query.next();