Query groups
This document guides developers on how to use RC's IM Web IMLib SDK to implement features such as retrieving joined groups and obtaining specified group information.
This feature is supported starting from version 5.12.0.
Enabling the Service
Before using this feature, you must enable the profile hosting service by submitting a ticket.
Group Query
You can query or search for groups you've joined.
Get Group Information
Call the getGroupsInfo method to retrieve group information. Supports retrieving information for all existing groups.
This method prioritizes local lookup. If the group information doesn't exist locally or the cached group information exceeds 10 minutes, it will fetch the latest group information from the server.
Interface
RongIMLib.getGroupsInfo(groupIds)
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
groupIds | string[] | Yes | Group ID list, supports up to 20 groups per query |
Example Code
// Required, group ID array, supports up to 20 groups per query.
const groupIds = ['group001','group002']
const res = await RongIMLib.getGroupsInfo(groupIds);
console.info('Get group information list', res);
Get Information for Specified Joined Groups
Use getJoinedGroups to retrieve information for groups the current user has joined, based on group IDs.
Interface
RongIMLib.getJoinedGroups(groupIds)
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
groupIds | string[] | Yes | Group ID list, supports up to 20 groups per query |
Example Code
const groupIds = ['group001', 'group002']; // Group ID array, maximum 20 groups per query
const res = await RongIMLib.getJoinedGroups(groupIds);
console.info('Batch get group information result', res);
Get Joined Group Information by Role
Use getJoinedGroupsByRole to paginate through joined groups based on member roles.
The IPagingQueryResult structure returned by Web currently doesn't support returning totalCount
.
Interface
RongIMLib.getJoinedGroupsByRole(option, role)
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
option | IPagingQueryOption | Yes | Pagination parameters, maximum 100 records per page. |
option.count | GroupMemberRole | Yes | Group member role. |
- For initial query, the
pageToken
parameter inoption
can be omitted or passed as''
(equivalent). - To fetch the next page, pass the
pageToken
returned from the previous query result.
- When
pageToken
isn't''
, more data is available. - When
pageToken
is''
, all data has been fetched. Passing''
again will return 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 Name (Electron)
Use searchJoinedGroups to search joined groups by name.
Interface
RongIMLib.searchJoinedGroups(groupName, option)
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
groupName | string | Yes | Group name search keyword. Cannot be empty, maximum 64 characters, supports fuzzy search (trim whitespace before query). |
option | IPagingQueryOption | No | Pagination parameters, maximum 200 records per page. |
- For initial query, the
pageToken
parameter inoption
can be omitted or passed as''
(equivalent). - To fetch the next page, pass the
pageToken
returned from the previous query result.
- When
pageToken
isn't''
, more data is available. - When
pageToken
is''
, all data has been fetched. Passing''
again will return 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 whitespace before query).
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);
}