Manage members

Update time: 2024/03/07 11:13:40

NIM SDK can query users, add or remove group members, and manage roles. All members are categorized into group owners, administrators, and plain members by permission.

How it works

TeamService provides methods for managing group members and implements the group member permission system and management.

A group can have members of three roles, group owner (owner), administrator (manager) and regular member (normal). For more information, see TeamMemberType.

  • The group owner is the group creator by default, and can be transferred by calling the transferTeam method.
  • Administrators are assigned by the group owner, and the group owner add administrators using addManagers.
  • After a user join the group, the user becomes regular member by default. The user can request other roles from the group owner.
  • TeamMemberType also contains the Apply type, indicating users that has sent join requests for approval.

Prerequisites

  • The group is created and the user is in the group. For more information, see Manage groups.
  • Listeners for group events are registered. For more information, see [Listeners for group events](https://doc.commsease.com/messaging/docs/zQyMzU4NzE?platform=flutter#Listeners for group events).

Manage administrators

Add administrators

Only the group owner have the permission to add administrators.

Group owners can add administrators by calling addManagers.

After the group owner adds an administrator, all group members will receive a notification of NIMMessageType.notification type and the trigger event is addTeamManager.

Parameters:

Parameter Description
teamId group ID
accounts accounts that are assigned administrator

Sample code:

dart// teamId is the group ID where the operation performs, accountList includes accounts to be assigned administrator
   final result = await NimCore.instance.teamService.addManagers(
          'teamId',
          ['accounts'],
        );

Remove administrators

Only the group owner have the permission to remove administrators.

Group owners can remove administrators by calling removeManagers.

If an administrator is removed, the user becomes a regular member. All group members will receive a notification of IMMessageType.notification and the trigger event is removeTeamManager.

Parameters:

Parameter Description
teamId group ID
managers accounts be be unassigned administrator

Sample code:

dart  final result = await NimCore.instance.teamService.removeManagers(
          'teamId',
          ['managers'],
        );

Edit the member profile

Edit the nickname of a group member

Only the group owner has the permission to edit the nickname of a group member.

Group owners can edit the nickname of a group member by calling updateMemberNick.

Parameters:

Parameter Description
teamId group ID
account Account whose nickname to be edited.
nick Group nickname

Sample code:

dart  final result = await NimCore.instance.teamService.updateMemberNick(
      'teamId',
      'account',
      'nick',
    );

Edit the extension field of the current user

Edit the extension field of the current user by calling updateMyMemberExtension.

Parameters:

Parameter Description
teamId group ID
extension New extension field (custom attribute)

Sample code:

dart  final result = await NimCore.instance.teamService.updateMyMemberExtension(
      'teamId',
      {'key':'value'},
    );

Mute members

Mute all members

Only the group owner has the permission to mute or unmute all members.

Mute or unmute all members by calling muteAllTeamMember.

Two modes are applied for muting all members.

  • If the mute mode muteMode is set to muteALL, all members include the group owner and administrators are muted.
  • If the mute mode muteMode is set to muteNormal, all members include only regular members are muted, not the group owner and administrators.

Parameters:

Parameter Description
teamId group ID
mute Whether all members are muted.
true: all members are muted.
false: all members are unmuted
.

Sample code:

final result = await NimCore.instance.teamService.muteAllTeamMember(
          'teamId',
          true,
        );

Mute a specified member

Only the group owner can mute a specified member.

Mute or unmute a specified member by calling muteTeamMember.

If a member is muted or unmuted, all group members will receive a notification of NIMMessageType.notification type and the trigger event is muteTeamMember.

Parameters:

Parameter Description
teamId group ID
/ account Account to be muted or unmuted
mute Whether a member is muted.
true: muted.
false: unmuted.

Sample code:

dart// Mute members
final result = await NimCore.instance.teamService.muteTeamMember(
          'teamId',
          'manager',
          true,
        );

Query group members

  • Since a group has a large number of members and the group member list is not required except the group member list interface, the SDK will not synchronize the group member data when logging in. The member list is loaded on demand. Only when the upper layer calls to obtain the group member list of the specified group, the SDK will evaluate whether synchronization is required.

  • Local storage of group member information in the SDK: When you leave a group or are removed from the group, the local database will continue to retain the group member information. Only the invalid flag is applied. At this time, you can still check the group member information using queryTeamMember. However, isInTeam returns false .

Query information about all groups members

Get the information about all group members by calling queryMemberList.

This operation may only read cached data from the local database or synchronize new data from the server. Therefore, it may take a long time.

Sample code:

dart final result = await NimCore.instance.teamService.queryMemberList(
          'teamId',
        );

Query a specified member

Get a specified member in a group by asynchronous calling queryTeamMember.

If the information about the group member is outdated in the local database, the SDK will gets the newest profile data from the server.

Parameters:

Parameter Description
teamId group ID
account Account to be queried

Sample code:

 final result = await NimCore.instance.teamService.queryTeamMember(
          'teamId',
          'account',
        );

Query the inviter of a group member

Query the inviter of a group member by calling getMemberInvitor.

If the value is empty, the member joined the group without invitation.

Parameters:

Parameter Description
tid Group ID
Accids The accounts whose inviters are queried. up to 200 accounts are allowed for a query.

Sample code:

// accids represents the member list of the query
   final result = await NimCore.instance.teamService.getMemberInvitor(
      'teamId',
      ['accids'],
    );

Query muted members in a group

Query muted members in a group by calling queryMutedTeamMembers.

  • This interface only returns the list of members that are muted by the muteTeamMember method.
  • To query the mute state of a group, call NIMTeam#muteMode and NIMTeam#isAllMute.
  • Query whether a user is muted by the muteTeamMember method using NIMTeamMember - isMute.
  • if all members are muted but are not muted by the muteTeamMember method, NIMTeamMember - isMute is still false.

Sample code:

// `members` are muted members
 final result = await NimCore.instance.teamService.queryMutedTeamMembers(
      'teamId',
    );

API reference

API
Description
addManagers Add administrators
removeManagers Remove administrators
updateMemberNick Update the nickname of a group member
updateMyMemberExtension Update the extension field of the current user.
muteAllTeamMember Mute all group members.
muteTeamMember Mute a group member.
queryMemberList Get the information about all group members.
queryTeamMember Query a specified member in a group.
getMemberInvitor Query the inviter of a specified member in a group
queryMutedTeamMembers Query muted members in a group.
Was this page helpful?
Yes
No
  • How it works
  • Prerequisites
  • Manage administrators
  • Add administrators
  • Remove administrators
  • Edit the member profile
  • Edit the nickname of a group member
  • Edit the extension field of the current user
  • Mute members
  • Mute all members
  • Mute a specified member
  • Query group members
  • Query information about all groups members
  • Query a specified member
  • Query the inviter of a group member
  • Query muted members in a group
  • API reference