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 group channels by user IDs

To filter group channels by user IDs, use includeMode in GroupChannelUserIdsFilter. 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.

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

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

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

A userIdsIncludeFilter parameter returns the current user's group channel list that includes partial or exact user IDs. Two different results can be returned according to the value of the queryType parameter.

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

// Only channel B 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);

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