/ SDKs / JavaScript
SDKs
Chat SDKs JavaScript v4
Chat SDKs JavaScript
Chat SDKs
JavaScript
Version 4

Filter group channels by user IDs

Copy link

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.

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

// Only channel A is returned in a result list through the groupChannels parameter of the callback function.
const channels = 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.

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

// Only channel B including {'Maya', 'Brett`, `Chelsea`} as a subset is returned in a result list.
const channels = await query.next();
JavaScriptTypeScript
const params = {
  userIdsIncludeFilter: ['Maya', 'Brett', 'Chelsea'],
  queryType: QueryType.OR,
};
const query = 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 = await query.next();