Managing group members
This document guides developers on how to use RongCloud IM Web IMLib SDK to implement features such as setting or querying group member profiles, adding or removing group administrators.
This feature is supported starting from version 5.12.0.
Service Activation
The information hosting service is enabled by default, and you can directly use this feature.
Group Members
You can query members of a specific group or set group member information.
Group Member Profile Change Callback
After successfully setting group member information for a specified group by calling the setGroupMemberInfo method, all group members will receive the group member profile change event callback Events.GROUP_MEMBER_INFO_CHANGED.
- The event listener should be registered globally and only once to avoid receiving duplicate event notifications.
- The event callback data type is IGroupMemberInfoChanged
Sample Code
RongIMLib.addEventListener(Events.GROUP_MEMBER_INFO_CHANGED, (data) => {
console.log('Group member profile change callback', data);
});
Paginated Retrieval of Group Member Information
Call the getGroupMembersByRole method to retrieve member information of a specified group by member role in paginated form. For role types, refer to GroupMemberRole.
The IPagingQueryResult structure returned on the Web side currently does not include the totalCount field.
Interface
RongIMLib.getGroupMembersByRole(groupId, role, option)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | string | Yes | Group ID. |
| role | GroupMemberRole | Yes | Group member role. Set to GroupMemberRole.UNDEF to retrieve all group members without distinguishing roles or positions. |
| option | IPagingQueryOption | Yes | Pagination request parameters. A maximum of 100 records can be queried per page. |
- For the first retrieval, the
pageTokenparameter inoptioncan be omitted or passed as'', with the same effect. - To retrieve the next page of data, pass the
pageTokenfrom the previous interface result.
- When
pageTokenis not'', it indicates that there is a next page, and retrieval can continue. - When
pageTokenis'', it indicates that all data has been retrieved, and passing''again will be treated as retrieving the first page of data.
Sample Code
const groupId = 'group001';
// Set to '' to remove. The string length should not exceed 64 characters. If the group alias already exists, it will be replaced, with the last setting taking precedence.
const role = RongIMLib.GroupMemberRole.UNDEF;
const option = {
// Required, range 1 ~ 100
count: 50,
}
const res = await RongIMLib.getGroupMembersByRole(groupId, role, option);
console.info('Paginated retrieval of group member information', res);
// Retrieve the next page
if (res && res.pageToken) {
const nextRes = await RongIMLib.getGroupMembersByRole(groupId, role, {
...option,
pageToken: res.pageToken
});
console.info('Paginated retrieval of group member information, retrieving the next page', nextRes);
}
Retrieve Group Member Information
Call the getGroupMembers method to retrieve detailed information of certain members in a specified group.
Interface
RongIMLib.getGroupMembers(groupId, userIds)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | string | Yes | Group ID. |
| userIds | string[] | Yes | Array of user IDs, with a maximum of 100. |
- If the current user is not in the group, group member information cannot be retrieved.
- Only supports querying information of existing group members. If
userIdscontains non-group member user IDs, they will be automatically filtered out and not returned.
Sample Code
const groupId = 'group001';
// If user01 is not in group001, [] will be returned
const userIds = ['user01'];
const res = await RongIMLib.getGroupMembers(groupId, userIds);
console.info('Retrieve group member information', res);
Search Group Member Information by Nickname (Electron Only)
Only supported on the Electron platform; not currently supported on Web.
Call the searchGroupMembers method to paginatedly search for group member information of a specified group in local groups.
- Prioritizes matching group member nicknames (nickname). If the nickname is empty, matches the username (name).
- Returns the member information if any field matches successfully.
Interface
RongIMLib.searchGroupMembers(groupId, name, option)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | string | Yes | Group ID. |
| name | string | Yes | Search name, supports fuzzy matching. Cannot be an empty string or pure spaces. Length should not exceed 64 characters. |
| option | IPagingQueryOption | Yes | Pagination request parameters, with a maximum of 100 records per page. |
- For the first retrieval, the
pageTokenparameter inoptioncan be omitted or passed as'', with the same effect. - To retrieve the next page of data, pass the
pageTokenfrom the previous interface result.
- When
pageTokenis not'', it indicates that there is a next page, and retrieval can continue. - When
pageTokenis'', it indicates that all data has been retrieved, and passing''again will be treated as retrieving the first page of data.
Sample Code
const groupId = 'group001';
// Cannot be empty or pure spaces, maximum length of 64 characters
// Supports fuzzy search queries. If the nickname is empty, searches the username.
const name = 'name';
const option = {
// Required, range 1 ~ 100
count: 50,
}
const res = await RongIMLib.searchGroupMembers(groupId, name, option);
console.info('Paginated retrieval of group member information by nickname', res);
// Retrieve the next page
if (res && res.pageToken) {
const nextRes = await RongIMLib.searchGroupMembers(groupId, name, {
...option,
pageToken: res.pageToken
});
console.info('Paginated retrieval of group member information by nickname, retrieving the next page', nextRes);
}
Set Group Member Information
Call the setGroupMemberInfo method to set group member information for a specified group.
- Upon successful execution, all group members will receive the group member profile change event notification Events.GROUP_MEMBER_INFO_CHANGED.
- The group member profile update permission
memberInfoEditPermissionis of type GroupMemberInfoEditPermission, determining whether group member profiles can be modified. If no permission is granted, an error code will be returned.
Interface
RongIMLib.setGroupMemberInfo(groupId, userId, nickname, extra)
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | string | Yes | Group ID. |
| userId | string | Yes | Group member user ID. |
| nickname | string | Yes | Group member nickname, with a maximum length of 64 characters. Cannot be pure spaces. |
| extra | string | No | Additional group member information, with a maximum length of 128 characters. |
Sample Code
const groupId = 'group001'; // Group ID
const userId = 'user01'; // Group member user ID
const nickname = 'nickname'; // Group member nickname, maximum length of 64 characters. Cannot be pure spaces.
const extra = 'extra info'; // Optional, additional group member information, maximum length of 128 characters.
const res = await RongIMLib.setGroupMemberInfo(groupId, userId, nickname, extra);
console.info('Result of setting group member information', res);
return res;
Group Administrators
You can add or remove group administrators.
Add Group Administrators
Call the addGroupManagers method to add group administrators.
- Only the group owner can call this interface.
- The maximum number of administrators in a group is 10.
- Upon successful addition, all group members will receive the Events.GROUP_OPERATION callback, where operation=5 (GroupOperation.ADD_MANAGER).
Interface
RongIMLib.addGroupManagers(groupId, userIds)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | String | Yes | Group ID. |
| userIds | string[] | Yes | User ID array. The users must be group members, with a maximum of 10 administrators that can be added at once. |
Example Code
const groupId = 'group001'; // Group ID
const userIds = ['user001', 'user002']; // User ID array. The users must be group members, with a maximum of 10 administrators that can be added at once.
const res = await RongIMLib.addGroupManagers(groupId, userIds);
console.info('Result of setting group administrators', res);
Remove Group Administrators
Call the removeGroupManagers method to remove group administrators.
Upon successful removal, all group members will receive the Events.GROUP_OPERATION callback, where operation=6 (GroupOperation.REMOVE_MANAGER).
Interface
RongIMLib.removeGroupManagers(groupId, userIds)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | String | Yes | Group ID. |
| userIds | Array | Yes | User ID array. A maximum of 10 administrators can be removed at once. |
Example Code
const groupId = 'group001'; // Group ID
const userIds = ['user001', 'user002']; // User ID array. A maximum of 10 administrators can be removed at once.
const res = await RongIMLib.removeGroupManagers(groupId, userIds);
console.info('Result of setting group administrators', res);
Members I Follow
Supports adding, removing, and querying members I follow in a group.
Features
-
The maximum number of members I follow is 200.
-
Messages sent by members I follow are not affected by conversation Do Not Disturb settings and will trigger notifications normally.
-
Push notification priority for messages sent by members I follow is as follows:
- Application-level Do Not Disturb (no push) > Message marked as silent in the message body > Sender is a member I follow > Conversation Do Not Disturb settings
- For details on Do Not Disturb, see Do Not Disturb Overview.
-
Upon successfully adding or removing members I follow, the user's other logged-in devices will receive the multi-device event callback Events.GROUP_FOLLOWS_CHANGED_SYNC.
Multi-Device Callback for Changes to Members I Follow
Upon successfully adding or removing members I follow, the user's other logged-in devices will receive this multi-device event callback.
- The event listener should be registered globally and only once to avoid duplicate notifications.
- The callback data type is IGroupFollowsChangedSync.
Example Code
RongIMLib.addEventListener(Events.GROUP_FOLLOWS_CHANGED_SYNC, (data) => {
console.log('Multi-device callback for changes to members I follow', data);
});
Add Members I Follow
Call the addGroupFollows method to add members I follow.
The maximum number of members I follow is 200.
Interface
RongIMLib.addGroupFollows(groupId, userIds)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | string | Yes | Group ID. |
| userIds | string[] | Yes | User ID array. A maximum of 100 users can be added at once. |
Example Code
const groupId = 'group001'; // Group ID
const userIds = ['user001', 'user002']; // User ID array. A maximum of 100 users can be added at once.
const res = await RongIMLib.addGroupFollows(groupId, userIds);
console.info('Result of adding members I follow', res);
Remove Members I Follow
Call the removeGroupFollows method to remove members I follow.
Interface
RongIMLib.removeGroupFollows(groupId, userIds)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | string | Yes | Group ID. |
| userIds | string[] | Yes | User ID array. A maximum of 100 users can be removed at once. |
Example Code
const groupId = 'group001'; // Group ID
const userIds = ['user001', 'user002']; // User ID array. A maximum of 100 users can be removed at once.
const res = await RongIMLib.removeGroupFollows(groupId, userIds);
console.info('Result of removing members I follow', res);
Query Members I Follow
Call the getGroupFollows method to query members I follow.
Interface
RongIMLib.getGroupFollows(groupId)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | string | Yes | Group ID. |
Example Code
const groupId = 'group001'; // Group ID
const res = await RongIMLib.getGroupFollows(groupId);
console.info('Result of querying members I follow', res);