Manage members

Update time: 2023/02/09 06:26:09

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

NIMTeamManager 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 (NIMTeamMemberTypeOwner), administrator (NIMTeamMemberTypeManager) and regular member (NIMTeamMemberTypeNormal). For more information, see NIMTeamMemberType.

  • The group owner is the group creator by default, and the ownership of a group can be transferred by calling the transferManagerWithTeam:newOwnerId:isLeave:completion: method.
  • The group owners assign administrators using addManagersToTeam:users:completion:.
  • After a user join the group, the user becomes regular member by default. The user can request other roles from the group owner.
  • NIMTeamMemberType also contains the NIMTeamMemberTypeApply type, indicating users that has sent join requests for approval.

Prerequisites

Manage administrators

Add administrators

Only the group owner have the permission to add administrators.

Add administrators by calling the addManagersToTeam:users:completion: method.

After the group owner adds an administrator, all group members will receive a notification of NIMMessageTypeNotification type and the trigger event is NIMTeamOperationTypeAddManager|

Parameters:

Parameter Description
teamId group ID
users Accounts to be unassigned administrator
completion Callback for completion

** Sample code:**

NSString *teamId = @"6271272396";
    /// users array
    NSArray<NSString *> *users = [NSArray arrayWithObjects:@"ios02", @"ios03", nil];
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// success
            NSLog(@"[Add manager in team %@ succeed.]", teamId);
            /// your code ...
        } else {
            /// failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// add administrator
    [[[NIMSDK sharedSDK] teamManager] addManagersToTeam:teamId
                                                  users:users
                                             completion:completion];

Remove an administrator

Only the group owner has the permission to remove administrators.

Remove administrators by calling removeManagersFromTeam:users:completion:.

If the group owner removed an administrator, the administrator becomes a regular member. All group members will receive a notification of NIMMessageTypeNotification type and the trigger event is NIMTeamOperationTypeRemoveManager|

Parameters:

Parameter Description
teamId group ID
users Accounts to be unassigned administrator
completion Callback for completion

** Sample code:**

NSString *teamId = @"6271272396";
    /// users array
    NSArray<NSString *> *users = [NSArray arrayWithObjects:@"ios02", nil];
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// success
            NSLog(@"[Remove manager in team %@ succeed.]", teamId);
            /// your code ...
        } else {
            /// failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Remove an administrator
    [[[NIMSDK sharedSDK] teamManager] removeManagersFromTeam:teamId
                                                       users:users
                                                  completion:completion];

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 updateUserNick:newNick:inTeam:completion:.

Parameters:

Parameter Description
teamId group ID
userId The account whose nickname in a group is edited.
newNick New nickname
completion Callback for completion.

** Sample code:**

NSString *userId = @"ios02";
    /// newNick New nickname
    NSString *newNick = @"ios02's new name";
    /// teamId Grouo ID
    NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Success
            NSLog(@"[Update user %@'s nickname to '%@' succeed.]", userId, newNick);
            /// your code ...
        } else {
            /// Failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Update the nickname of a group member
    [[[NIMSDK sharedSDK] teamManager] updateUserNick:userId
                                             newNick:newNick
                                              inTeam:teamId
                                          completion:completion];

Edit the extension field of the current user

Edit multiple fields of the profile of the current user by calling the updateMyCustomInfo:inTeam:completion: method

After modification, other online users will automatically get the modified attributes synchronously.

Parameters:

Parameter Description
teamId group ID
newInfo new custom attributes
completion Callback for completion.

** Sample code:**

/// newInfo new custom attributes
    NSString *newInfo = @"My custom attribute";
    /// teamId Grouo ID
    NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Update my custom info as %@ succeed.]", newInfo);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Update the attributes of the the current user’s profile.
    [[[NIMSDK sharedSDK] teamManager] updateMyCustomInfo:newInfo
                                                  inTeam:teamId
                                              completion:completion];

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 the updateMuteState:inTeam:completion: method.

Two modes are applied for muting all members.

  • If the mute mode NIMTeamAllMuteMode is set to NIMTeamAllMuteModeMuteAll, all members, including the group owner and administrators, are muted.
  • If the mute mode NIMTeamAllMuteMode is set to NIMTeamAllMuteModeMuteNormal, only regular members, not the group owner and administrators, are muted.

Parameters:

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

** Sample code:**

/// mute: whether a member is muted. YES: true, NO: false.
    BOOL mute = NO;
    /// teamId Grouo ID
    NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Update mute state to %@ succeed.]", mute ? @"YES" : @"NO");
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Update the mute state
    [[[NIMSDK sharedSDK] teamManager] updateMuteState:mute
                                               inTeam:teamId
                                           completion:completion];

Mute a specified member

Only the group owner can mute a specified member.

Mute or unmute a specified member by calling the updateMuteState:userId:inTeam:completion: method.

After a member is muted, all group members will receive a notification of NIMMessageTypeNotification type and the trigger event is NIMTeamOperationTypeMute.

Parameters:

Parameter Description
teamId group ID
userId The member that is muted or unmuted.
mute Whether a member is muted.
true: muted
false: unmuted
completion Callback for completion.

** Sample code:**

/// mute: whether a member is muted. YES: true, NO: false.
    BOOL mute = NO;
    /// userId The ID of the muted or unmuted member
    NSString *userId = @"ios01";
    /// teamId Grouo ID
    NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamHandler completion = ^(NSError * __nullable error)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Update %@'s mute state to %@ succeed.]", userId, mute ? @"YES" : @"NO");
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Update the mute state of a member
    [[[NIMSDK sharedSDK] teamManager] updateMuteState:mute
                                               userId:userId
                                               inTeam:teamId
                                           completion:completion];

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.
  • For the data of group members that have been synced or retrieved from the server, the SDK will cache the data on the local storage.
  • Local storage of group member information in the SDK: If you leave a group or are removed from the group, the local database will continue to retain the group member information with the invalid flag.

Query information about all groups members

Get the information about all group members by calling the fetchTeamMembers:completion: method.

  • In most cases, this request fetches the data from the local cache and sync the data with the server. However, due to the large amount of information about group members, the SDK delays retrieving the information after login. Considering the network and other issues, the SDK may not cache the group member information in time, so the calling will be an asynchronous operation (for incremental data) with a HTTP request. This interface will request the data of group users that are not cached locally, but will not trigger the - (void)onUserInfoChanged: callback
  • The obtained data of group members only have group-related data stored on the CommsEase server. You must combine the user data managed by the app server for display.

** Sample code:**

NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamMemberHandler completion = ^(NSError * __nullable error, NSArray<NIMTeamMember *> * __nullable members)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Fetch team %lu menbers succeed.]", (unsigned long)members.count);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Fetch the data of group members
    [[[NIMSDK sharedSDK] teamManager] fetchTeamMembers:teamId
                                            completion:completion];

Fetch the data of group members from the server

Fetch the data of group members from the server by calling the fetchTeamMembersFromServer:completion: method.

The interface is used to get the list of group members by making a HTTP request, which is different from the fetchTeamMembers interface. This interface is an asynchronous operation (for incremental data) that must have an HTTP request. This interface will request the data of group users that are not cached locally, but will not trigger the - (void)onUserInfoChanged: callback

** Sample code:**

NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamMemberHandler completion = ^(NSError * __nullable error, NSArray<NIMTeamMember *> * __nullable members)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Fetch team %lu menbers from server succeed.]", (unsigned long)members.count);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Fetch the data of group members from the server
    [[[NIMSDK sharedSDK] teamManager] fetchTeamMembersFromServer:teamId
                                                      completion:completion];

Query a specified member

Fetch the profile of a specified member by calling the teamMember:inTeam: method.

Parameters:

Parameter Description
teamId group ID
userId The account whose data is fetched.

** Sample code:**

NSString *userId = @"ios01";
    /// teamId Grouo ID
    NSString *teamId = @"6271272396";
    /// Get the data of a group member
    NIMTeamMember *userConcrete = [[[NIMSDK sharedSDK] teamManager] teamMember:userId
                                                                        inTeam:teamId];

Query the inviter of a group member

Query the inviter of a group member by calling the fetchInviterAccids:withTargetMembers:completion: method.

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

Parameters:

Parameter Description
teamID Group ID
memberIDs Accounts whose inviters are queried. up to 200 accounts are allowed at a time
completion Callback for completion

** Sample code:**

NSString *teamId = @"6271272396";
    /// users array
    NSArray<NSString *> *users = [NSArray arrayWithObjects:@"ios01", nil];
    /// completion Callback for completion
    NIMTeamFetchInviterAccidsHandler completion = ^(NSError * _Nullable error,
                                        NSDictionary<NSString *,NSString *> * _Nullable inviters)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Fetch %@’s inviter: %@ succeed.]", users[0], inviters[users[0]]);
            /// your code ...
        } else {
            /// Operation failed
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Get the inviter of a group member
    [[[NIMSDK sharedSDK] teamManager] fetchInviterAccids:teamId
                                       withTargetMembers:users
                                              completion:completion];

Query muted members in a group

Query muted members in a group by calling the fetchTeamMutedMembers:completion: method.

  • This interface only returns the list of members that are muted by the updateMuteState:userId method.
  • To query all muted members of a group, call the inAllMuteMode method.
  • Query whether a user is muted by calling the NIMTeamMember#isMuted method.
  • if all members are muted but not muted by the updateMuteState:userId method, isMuted is NO.
  • In most cases, this request fetches the data from the local cache and sync the data with the server. However, due to the large amount of information about group members, the SDK delays retrieving the information after login. Considering the network and other issues, the SDK may not cache the group member information in time, so the calling will be an asynchronous operation (for incremental data) with a HTTP request. This interface will request the data of group users that are not cached locally, but will not trigger the onUserInfoChanged callback.

** Sample code:**

NSString *teamId = @"6271272396";
    /// completion Callback for completion
    NIMTeamMemberHandler completion = ^(NSError * __nullable error, NSArray<NIMTeamMember *> * __nullable members)
    {
        if (error == nil) {
            /// Operation success
            NSLog(@"[Fetch team %lu menbers succeed.]", (unsigned long)members.count);
            /// your code ...
        } else {
            /// Operation failure
            NSLog(@"[NSError message: %@]", error);
        }
    };
    /// Fetch the muted members in a group
    [[[NIMSDK sharedSDK] teamManager] fetchTeamMutedMembers:teamId
                                                 completion:completion];

API reference

API
Description
addManagersToTeam Add administrators.
removeManagersFromTeam Remove administrators.
updateUserNick Update the nickname of a member.
updateMyCustomInfo Update the custom information of the current user in a group
updateMuteState:inTeam Mute all group members.
updateMuteState:userId Mute a specified member.
fetchTeamMembers Fetch the data of all group members.
fetchTeamMembersFromServer Fetch the data of group members from the server.
teamMember Fetch the data of a specified group member.
fetchInviterAccids Query the inviter of a group member.
fetchTeamMutedMembers Query muted members in a group.
isMyTeam Query whether a user has the membership of a group by group ID.
Was this page helpful?
Yes
No
  • How it works
  • Prerequisites
  • Manage administrators
  • Add administrators
  • Remove an administrator
  • 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
  • Fetch the data of group members from the server
  • Query a specified member
  • Query the inviter of a group member
  • Query muted members in a group
  • API reference