Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Check group membership

Check whether a specified user is a member of the target group.

Copy

The HarmonyOS API accepts both group ID and user ID, allowing you to check either the current account or other users where permitted.

Code example

import sdk, { IsJoinGroupReq, IsJoinGroupResp } from '@openimsdk/imsdk';

const request: IsJoinGroupReq = {
  groupID: groupID,
  userID: currentUserID,
};
const response: IsJoinGroupResp = await sdk.isJoinGroup(request);
if (response.joined) {
  showGroupMemberActions();
}

Parameters

ParameterTypeRequiredDescription
groupIDstringYesTarget group identifier.
userIDstringYesUser ID to check for membership.

Return value

Returns a Promise resolving to IsJoinGroupResp:

PropertyTypeDescription
joinedbooleantrue if the user is currently in the group; otherwise false.

State changes after the call

This method checks membership snapshot status at the time of invocation and does not fire events. To continuously maintain membership state for the current account, listen to group joined, left, and dismissed events as described in Group overview, and recalibrate after reconnects or key lifecycle operations.