Skip to main content

Group Query

This document guides developers on how to use the RC IMLib SDK to implement functionalities such as retrieving joined groups and obtaining specific group information.

Service Activation

The User Profile Hosting service is enabled by default, allowing you to use this feature directly.

Group Query

You can query or search for groups you have joined.

Retrieve Group Information

You can call the getGroupsInfo method to retrieve group information.

  • This method prioritizes local lookup. When the user is not in the group, or if the local group information cache exceeds 10 minutes, it will fetch the latest group information from the server.
  • A single call supports retrieving information for up to 20 groups.

Code Example

// Group ID list
List<String> groupIds = new ArrayList<>();
groupIds.add("groupId1");
groupIds.add("groupId2");
groupIds.add("groupId3");
RongCoreClient.getInstance().getGroupsInfo(groupIds, new IRongCoreCallback.ResultCallback<List<GroupInfo>>() {
@Override
public void onSuccess(List<GroupInfo> groupInfos) {
// Successfully retrieved group information
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Failed to retrieve group information
}
});

Retrieve Information for Specified Joined Groups

You can use getJoinedGroups to retrieve group information based on the group IDs of the current user's joined groups.
This interface supports batch retrieval—you can pass multiple groupId values to fetch information for up to 20 groups at once.

Code Example

// Group ID list
List<String> groupIds = new ArrayList<>();
groupIds.add("groupId1");
groupIds.add("groupId2");
groupIds.add("groupId3");
RongCoreClient.getInstance().getJoinedGroups(groupIds, new IRongCoreCallback.ResultCallback<List<GroupInfo>>() {
@Override
public void onSuccess(List<GroupInfo> groupInfos) {
// Successfully retrieved
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Failed to retrieve
}
});

Retrieve Joined Group Information by Role

You can use getJoinedGroupsByRole to paginate and retrieve joined groups based on member roles.

This interface supports returning the total count for the current query condition, accessible via PagingQueryOption's getTotalCount().

Parameter Description

Group member role GroupMemberRole enumeration:

Enum ValueMember Role
UndefUndefined role (using this enum queries all member types)
NormalRegular group member
ManagerAdministrator
OwnerGroup Owner
tip

Pagination Notes:

  1. For the first retrieval, PagingQueryOption's pageToken does not need to be set (not setting it, setting it to null, or setting it to "" has the same effect).
  2. To retrieve the second page, pass the pageToken from the PagingQueryResult returned by the first retrieval.
    • If it is not "", you can pass this value to retrieve the next page until pageToken returns "", indicating completion.
    • If it is "", there are no more pages or retrieval is complete. Passing "" will retrieve the first page again.

Example Code

{
//...
String pageToken = "";
getJoinedGroupsByRole(pageToken);
//...
}

public void getJoinedGroupsByRole(String pageToken) {
// Use the role parameter to specify retrieving groups for all member roles
GroupMemberRole role = GroupMemberRole.Undef;
// Pagination request parameters
PagingQueryOption option = new PagingQueryOption();
// Set page size (range: [1~100]).
option.setCount(20);
// Pagination token
option.setPageToken(pageToken);
// Sort by join time (ascending/descending). true: ascending; false: descending
option.setOrder(false);
RongCoreClient.getInstance().getJoinedGroupsByRole(role, option, new IRongCoreCallback.PageResultCallback<GroupInfo>() {
@Override
public void onSuccess(PagingQueryResult<GroupInfo> result) {
if (!TextUtils.isEmpty(result.getPageToken())) {
// Use the returned pageToken to retrieve the next page
getJoinedGroupsByRole(result.getPageToken());
} else {
// Retrieval complete
}
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Retrieval failed
}
});
}

Search Joined Groups by Group Name

You can use searchJoinedGroups to search for joined groups by group name.
This interface supports returning the total count for the current query condition, accessible via PagingQueryOption's getTotalCount().

tip

Pagination Notes:

  1. For the first retrieval, PagingQueryOption's pageToken does not need to be set (not setting it, setting it to null, or setting it to "" has the same effect).
  2. To retrieve the second page, pass the pageToken from the PagingQueryResult returned by the first retrieval.
    • If it is not "", you can pass this value to retrieve the next page until pageToken returns "", indicating completion.
    • If it is "", there are no more pages or retrieval is complete. Passing "" will retrieve the first page again.

Code Example

{
//...
// Pagination token (setting null or "" has the same effect)
String pageToken = "";
searchJoinedGroups(pageToken);
//...
}

public void searchJoinedGroups(String pageToken) {
// Group name
String groupName = "groupName";
// Pagination request parameters
PagingQueryOption option = new PagingQueryOption();
// Set page size (range: [1~200]).
option.setCount(20);
// Pagination token
option.setPageToken(pageToken);
// Sort by join time (ascending/descending). true: ascending; false: descending.
option.setOrder(false);
RongCoreClient.getInstance().searchJoinedGroups(groupName, option, new IRongCoreCallback.PageResultCallback<GroupInfo>() {
@Override
public void onSuccess(PagingQueryResult<GroupInfo> result) {
if (!TextUtils.isEmpty(result.getPageToken())) {
// Use the returned pageToken to retrieve the next page
searchJoinedGroups(result.getPageToken());
} else {
// Retrieval complete
}
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Retrieval failed
}
});
}