Query groups
This document guides developers on how to use the RC IM Web IMLib SDK to implement functionalities such as retrieving joined groups and obtaining specified group information.
This feature is supported starting from version 5.12.0.
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.
Get Group Information
You can call the getGroupsInfo method to retrieve group information. This supports fetching details for all existing groups.
This method prioritizes local lookup. If the group information is not found locally or the cached group data is older than 10 minutes, it will fetch the latest group information from the server.
Interface
RongIMLib.getGroupsInfo(groupIds)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupIds | string[] | Yes | List of group IDs. A single query supports up to 20 groups. |
Example Code
// Required: Array of group IDs. A single query supports up to 20 groups.
const groupIds = ['group001','group002']
const res = await RongIMLib.getGroupsInfo(groupIds);
console.info('Get group information list', res);
Get Information for Specified Joined Groups
You can use getJoinedGroups to retrieve information for groups the current user has joined, based on group IDs.
Interface
RongIMLib.getJoinedGroups(groupIds)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupIds | string[] | Yes | List of group IDs. A single query supports up to 20 groups. |
Example Code
const groupIds = ['group001', 'group002']; // Array of group IDs. A single query supports up to 20 groups.
const res = await RongIMLib.getJoinedGroups(groupIds);
console.info('Batch get group information result', res);
Get Joined Group Information by Role
You can use getJoinedGroupsByRole to paginate and retrieve joined groups based on member roles.
The IPagingQueryResult structure returned by the Web SDK currently does not support returning totalCount.
Interface
RongIMLib.getJoinedGroupsByRole(option, role)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| option | IPagingQueryOption | Yes | Pagination parameters. A single query supports up to 100 records. |
| option.count | GroupMemberRole | Yes | Group member role. |
- For the first query, the
pageTokenparameter inoptioncan be omitted or set to'', with the same effect. - To fetch the next page, pass the
pageTokenreturned in the previous query result.
- If
pageTokenis not'', it indicates there are more pages to fetch. - If
pageTokenis'', it means all data has been fetched. Passing''again will retrieve the first page.
Example Code
const option = {
// Required, range: 1 ~ 100
count: 50,
}
const role = GroupMemberRole.UNDEF; // Group member role. GroupMemberRole.UNDEF retrieves all roles.
const res = await RongIMLib.getJoinedGroupsByRole(option, role);
console.info('Get user\'s joined groups result', res);
// Fetch next page
if (res && res.pageToken) {
const nextRes = await RongIMLib.getJoinedGroupsByRole({
...option,
pageToken: res.pageToken
}, role,);
console.info('Get user\'s joined groups, fetch next page', nextRes);
}
Search Joined Groups by Group Name (Electron)
You can use searchJoinedGroups to search for joined groups.
Interface
RongIMLib.searchJoinedGroups(groupName, option)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupName | string | Yes | Group name search keyword. Cannot be empty, maximum 64 characters. Supports fuzzy search. Trim leading/trailing spaces before querying. |
| option | IPagingQueryOption | No | Pagination parameters. A single query supports up to 200 records. |
- For the first query, the
pageTokenparameter inoptioncan be omitted or set to'', with the same effect. - To fetch the next page, pass the
pageTokenreturned in the previous query result.
- If
pageTokenis not'', it indicates there are more pages to fetch. - If
pageTokenis'', it means all data has been fetched. Passing''again will retrieve the first page.
Example Code |
const option = {
// Required, range: 1 ~ 200
count: 50,
}
const groupName = 'groupName'; // Group name search keyword. Cannot be empty, maximum 64 characters. Supports fuzzy search. Trim leading/trailing spaces before querying.
const res = await RongIMLib.searchJoinedGroups(groupName, option);
console.info('Search joined groups', res);
// Fetch next page
if (res && res.pageToken) {
const nextRes = await RongIMLib.searchJoinedGroups(groupName, {
...option,
pageToken: res.pageToken
});
console.info('Search joined groups, fetch next page', nextRes);
}