Group Management (iOS)

Last updated: 2021-10-15 16:05:11

    Group Types

    Instant Messaging (IM) supports the following group types:

    • A work group for friends (Work) is like an ordinary WeChat group. After a work group is created, a user can only join the group by being invited by a friend who is a member of the group. The invitation does not need to be accepted by the invitee or approved by the group owner.
    • A public group (Public) is like a QQ group. After a public group is created, the group owner can designate group admins. To join the group, a user needs to search for the group ID and send a request, and the request needs to be approved by the group owner or an admin before the user can join the group.
    • A meeting group (Meeting) allows users to join and exit freely and supports viewing message history from before the user joined the group. Meeting groups are ideal for scenarios that integrate Tencent Real-Time Communication (TRTC), such as audio and video conferences and online education.
    • A live streaming group (AVChatRoom) allows users to join and exit freely, supports unlimited number of members and does not store message history. Livestreaming groups can be used with Live Video Broadcasting (LVB) to support the on-screen comment chatting scenario.

    The following table describes the features and limitations of each group type:

    Feature Work Group for Friends (Work) Public Group (Public) Meeting Group (Meeting) Live Streaming Group (AVChatRoom)
    Available member roles Group owner and ordinary member Group owner, group admin, and ordinary member Group owner, group admin, and ordinary member Group owner and ordinary member
    Requesting to join a group Not supported Supported with group owner or group admin approval required Supported with no approval required Supported with no approval required
    Joining group via invitation by a member Supported Not supported Not supported Not supported
    Group owner quitting group Supported Not supported Not supported Not supported
    Who can modify group profile Any group member Group owner and group admin Group owner and group admin Group owner
    Who can kick group members out of group Group owner Group owner and group admin. Group admin can only remove ordinary group members. Group members cannot be removed. The same effect can be achieved by muting members.
    Who can mute members Muting members is not supported Group owner and group admin. Group admin can only mute ordinary group members. Group owner
    Unread count Supported Supported Not supported Not supported
    Viewing message history earlier than user's entry time Not supported Not supported Supported Not supported
    Retaining message history in the cloud Not supported
    Number of groups
    • Trial Edition: up to 100 existing groups, and disbanded groups do not count against the quota
    • Pro Edition or Flagship Edition: unlimited
    • Trial Edition: up to 10 existing groups, and disbanded groups do not count against the quota
    • Pro Edition: up to 50 existing groups, and disbanded groups do not count against the quota
      You can upgrade to unlimited number of live streaming groups by purchasing value-added service
    • Flagship Edition: unlimited
    Number of group members
    • Trial Edition: 20 per group
    • Pro Edition: 200 per group by default, can be increased to 2,000 per group via value-added service
    • Flagship Edition: 2,000 per group, can be increased to 6,000 per group via value-added service
    Unlimited number of group members
    Note:

    In the Pro Edition or Flagship Edition SDKAppID, the maximum net increase in group quantity per day is 10,000 for all group types. Free peak group count is 100,000 per month, and you will need to pay for usage exceeding the free quota.

    Group Management

    Creating a group

    Simple API

    You can quickly create a group by calling the createGroup API and specifying groupType, groupID, and groupName.

    Advanced API

    If you want to initialize group information (for example, group introduction, group profile photo, and initial group members) when creating a group, call the createGroup API in the V2TIMManager+Group.h management class.

    // Sample code: create a work group using the advanced createGroup API 
    V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
    info.groupName = @"testWork";
    info.groupType = @"Work";
    NSMutableArray *memberList = [NSMutableArray array];
    V2TIMCreateGroupMemberInfo *memberInfo = [[V2TIMCreateGroupMemberInfo alloc] init];
    memberInfo.userID = @"vinson";
    [memberList addObject:memberInfo];
    [[V2TIMManager sharedInstance] createGroup:info memberList:memberList succ:^(NSString *groupID) {
      // Group created successfully
    } fail:^(int code, NSString *msg) {
      // Failed to create the group
    }];
    
    • The value of groupType is a string and can be one of “Work”, “Public”, “Meeting”, and “AVChatRoom”. To learn about the differences among group types, see Group Types.
    • groupID specifies the group ID, which uniquely identifies a group. Do not create groups with the same groupID in a SDKAppID. If you set groupID to nil, you will be assigned a group ID by default.
    • groupName specifies the group description, which has a maximum length of 30 bytes.

    Joining a group

    The processes for joining groups of different types are described as follows:

    Type Work Group (Work) Social Networking Group (Public) Temporary Meeting Group (Meeting) Live Streaming Group (AVChatRoom)
    How to join group Must be invited by group member User joins group after request is approved by group owner or admin User can join freely User can join freely

    Scenario 1: users can join and quit the group freely

    Meeting groups (Meeting) and live streaming groups (AVChatRoom) can be used for interactive scenarios where users join and exit groups frequently, such as online conference and runway live streaming. The group joining procedure is therefore the simplest.

    After a user successfully joins a group by calling joinGroup, all group members (including the joined user), receive the onMemberEnter callback.

    Scenario 2: users must be invited to join the group

    Resembling WeChat and WeCom groups, work groups (Work) are suitable for communication in work environments. The interaction pattern is designed to disable proactive group joining and only allows users to be invited to join the group by group members.

    A group member calls inviteUserToGroup to invite a user to group, then all group members (including the inviter) receive the onMemberInvited callback.

    Scenario 3: users join the group after requests are approved

    Social networking groups (Public) are similar to the interest groups and tribes in QQ. Any user can request to join the group, but will not become a member of the group until the request is approved by the group owner or admin. While approval is required by default, the group owner or admin can call the setGroupInfo API to set the group joining option (V2TIMGroupAddOpt) to "forbid anyone to join" which is tighter, or to "disable the approval process", which is more flexible.

    • V2TIM_GROUP_ADD_FORBID: forbid anyone to join the group
    • V2TIM_GROUP_ADD_AUTH: (default) group owner or admin approval is required for group joining.
    • V2TIM_GROUP_ADD_ANY: disable the approval process to allow any user to join the group.

    The following diagram illustrates the process of group joining that requires approval:

    1. The user sends a request to join the group
      The user calls joinGroup to join the group.
    2. The group owner or admin process the group joining application
      After the onReceiveJoinApplication callback is received, the group owner or admin calls getGroupApplicationList to get the list of group joining applications, and approves or rejects an application with acceptGroupApplication or refuseGroupApplication.
    3. The user receives the result
      The user receives the onApplicationProcessed callback in V2TIMGroupListener. If isAgreeJoin is true, the application is approved, otherwise the application is rejected. If the application is approved, all members (including the requestor) receive the onMemberEnter callback.

    Quitting a group

    Call quitGroup to quit a group. The user who quits the group then receives the onQuitFromGroup callback and other group members receive the onMemberLeave callback.

    Note:

    For group owner of social networking group (Public), temporary meeting group (Meeting), and live streaming group (AVChatRoom) who is not allowed to quit the group, the group owner can disband the group.

    Deleting groups

    Call dismissGroup to disband a group. Then all group members receive the onGroupDismissed callback.

    Note:

    • For a social networking group (Public), temporary meeting group (Meeting), and live streaming group (AVChatRoom), the group owner can disband the group at any time.
    • For a work group (Work), the group owner does not have the privilege to disband the group. To disband the group, you must have your service server call the RESTful API Disbanding a Group.

    Getting the list of joined groups

    Call getJoinedGroupList to get a list of work groups (Work), social networking groups (Public), and temporary meeting groups (Meeting) the current user has joined. Live streaming groups (AVChatRoom) will not be included in this list.

    Group Profiles and Group Settings

    Getting group profiles

    Call getGroupsInfo to get the group profile of one or more groups at a time. To get the group profiles of multiple groups by a single call, pass in multiple groupID at a time.

    Modifying group profiles

    Call setGroupInfo to modify the group profile. When the modification is complete, all group members receive the onGroupInfoChanged callback.

    Note:

    • For work groups (Work), all group members can modify the basic group profile.
    • For social networking groups (Public) and temporary meeting groups (Meeting), only the group owner and admin can modify the basic group profile.
    • For live streaming groups (AVChatRoom), only the group owner can modify the group profile.
    // Sample code: modify group profile
    V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
    info.groupID = @"the ID of the group for which you want to modify the group profile";
    info.faceURL = @"http://xxxx";
    [[V2TIMManager sharedInstance] setGroupInfo:info succ:^{
      // Group profile modified successfully
    } fail:^(int code, NSString *msg) {
      // Failed to modify the group profile
    }];
    

    Setting the group message receiving option

    Any group member can call the setGroupReceiveMessageOpt API to modify the group message receiving option. Available values are as follows:

    • V2TIM_GROUP_RECEIVE_MESSAGE: messages will be received when the user is online and APNs push notifications will be received when the user is offline.
    • V2TIM_GROUP_NOT_RECEIVE_MESSAGE: no group messages will be received.
    • V2TIM_GROUP_RECEIVE_NOT_NOTIFY_MESSAGE: messages will be received when the user is online and no push notification will be received when the user is offline.

    The group message receiving option allows you to mute group messages:

    • No group message will be received
      With the group message receiving option set to V2TIM_GROUP_NOT_RECEIVE_MESSAGE, no group message will be received, and the conversation list will not be updated.
    • Group messages will be received but the user will not be notified. A badge without the unread count will be displayed on the conversation list interface
      Note:

      This mode requires the unread count feature and therefore it applies only to work groups (Work) and social networking groups (Public).

      With the group message receiving option set to V2TIM_GROUP_RECEIVE_NOT_NOTIFY_MESSAGE, when new group messages are received and the conversation list needs to update, get the unread count through unreadCount. Use recvOpt to verify that the group message receiving option is V2TIM_GROUP_RECEIVE_NOT_NOTIFY_MESSAGE and then display a badge without the unread count.

    Group Attributes (Custom Group Fields)

    New custom group fields, also called group attributes, are designed based on API 2.0. They have the following features:

    1. You can CRUD group attributes in the client instead of console.
    2. You can configure up to 16 group attributes. The size of each group attribute can be up to 4 KB, and the total size of all group attributes can be up to 16 KB.
    3. Only live streaming groups (AVChatRoom) support group attributes.
    4. The initGroupAttributes, setGroupAttributes, and deleteGroupAttributes APIs each can be called by the SDK for up to 10 times per 5 seconds, and the 8511 error code will be called back if the limit is exceeded. The APIs each can be called by the backend for up to 5 times per second, and the 10049 error code will be called back if the limit is exceeded.
    5. The getGroupAttributes API can be called by the SDK for up to 20 times per 5 seconds.

    With group attributes, you can manage the seats of audio chat rooms. When a user mics on, you can set a group attribute to manage the information of the user. When the user mics off, you can delete the group attribute. Other members can get the list of group attributes to display the seat list.

    Initializing group attributes

    Call the initGroupAttributes API to initialize group attributes. If the group already has group attributes, the existing group attributes will be cleared.

    Setting group attributes

    Call the setGroupAttributes API to set group attributes. If the group attributes to set do not exist, they will be automatically added.

    Deleting group attributes

    Call the deleteGroupAttributes API to delete specified group attributes. If the keys field is set to nil, all group attributes will be cleared.

    Getting group attributes

    Call the getGroupAttributes API to get specified group attributes. If the keys field is set to nil, all group attributes will be got.

    Updating group attributes

    If group attributes have any updates, all group attribute fields will be called back via the onGroupAttributeChanged API.

    Group Member Management

    Getting the group member list

    Call getGroupMemberList to get the list of group members of a given group. The list contains profile information about individual members, such as user ID (userID), group name card (nameCard), profile photo (faceUrl), nickname (nickName), and time of joining group (joinTime).
    As a group might have a large number of members (for example, 5,000+), this API supports two advanced attributes: filter and nextSeq.

    Filters

    When calling the getGroupMemberList API, you can specify filter to pull the information list of certain roles.

    Filter Description
    V2TIM_GROUP_MEMBER_FILTER_ALL Pull the information list of all group members
    V2TIM_GROUP_MEMBER_FILTER_OWNER Pull the information list of the group owner
    V2TIM_GROUP_MEMBER_FILTER_ADMIN Pull the information list of the group admin
    V2TIM_GROUP_MEMBER_FILTER_COMMON Pull the information list of all group members
    // Sample code: pull the profile of the group owner using the filter parameter
    [[V2TIMManager sharedInstance] getGroupMemberList:@"testGroup" filter:V2TIM_GROUP_MEMBER_FILTER_OWNER 
    nextSeq:0 succ:^(uint64_t nextSeq, NSArray<V2TIMGroupMemberInfo *> *memberList) {
      // Pulled successfully
    } fail:^(int code, NSString *msg) {
      // Messages fail to be pulled
    }];
    

    Pulling paginated results with nextSeq

    In many cases, it makes more sense for the user interface to display the first page of the group member list instead of the complete list. More group members can be pulled when the user clicks Next Page or pull the list to refresh. For this scenario, you can apply the method of pulling paginated results.

    The getGroupMemberList API returns a maximum of 50 members at a time. You can use the pagination flag nextSeq to pull the paginated group member list. In the first attempt to pull the group member list, enter 0 for nextSeq. When the first pull succeeds, the getGroupMemberList callback result V2TIMGroupMemberInfoResult contains the nextSeq field.

    • If nextSeq is 0, the complete group member list has been pulled.
    • If nextSeq is greater than 0, there remains group member information to be pulled. You can then decide whether to make another call to pull group member information based on the user’s action on the UI. In the second pull, you need to pass the nextSeq in the V2TIMGroupMemberInfoResult returned from the previous pull as parameter to the getGroupMemberList API.
    // Sample code: pull the paginated group member list using nextSeq
    [[V2TIMManager sharedInstance] getGroupMemberList:@"testGroup" filter:V2TIM_GROUP_MEMBER_FILTER_ALL nextSeq:0 
    succ:^(uint64_t nextSeq, NSArray<V2TIMGroupMemberInfo *> *memberList) {
      // If nextSeq is greater than 0, make another pull
      if (nextSeq > 0) {
          [[V2TIMManager sharedInstance] getGroupMemberList:@"testGroup" filter:V2TIM_GROUP_MEMBER_FILTER_ALL 
                  nextSeq:nextSeq succ:^(uint64_t nextSeq, NSArray<V2TIMGroupMemberInfo *> *memberList) {
              // The second pull succeeded
          } fail:^(int code, NSString *msg) {
              // The second pull failed
          }];
      }
      // The first pull succeeded
    } fail:^(int code, NSString *msg) {
      // The first pull failed
    }];
    

    Getting group member profiles

    Call getGroupMembersInfo to get the profile of group members in batches. You can pass in multiple userID at a time to improve network transmission efficiency.

    Modifying group member profiles

    The group owner or admin can call the setGroupMemberInfo API to modify information of group members, including group name card (nameCard), group member role (role), and muting duration (muteUntil).

    Muting group members

    The group owner or admin can mute a group member and set muting duration (in seconds) via muteGroupMember. Muting information is stored in the muteUntil field of the group member. After the group member is muted, all group members (including the muted member) receive the onMemberInfoChanged callback.
    The group owner or admin can mute the entire group via the setGroupInfo API by setting allMuted to true. There is no time limit for muting a group. To unmute a group, set allMuted to NO.

    Removing group members

    The group owner or admin can call the kickGroupMember API to remove a group member. As a live streaming group (AVChatRoom) can have unlimited members, it does not support the API. You can use muteGroupMember to achieve the same effect instead.
    After the member is removed, all group members (including the removed member) receive the onMemberKicked.

    Changing group member roles

    The group owner can call setGroupMemberRole to change the role of a member of social networking group (Public) or temporary meeting group (Meeting). Roles available for changing are ordinary members and group admins.

    • After a member is set as group admin, all group members (including the new admin) receive the onGrantAdministrator callback.
    • After the admin role is removed for a member, all group members (including the member with admin role removed) receive the onRevokeAdministrator callback.

    Transferring a group

    The group owner can call transferGroupOwner to transfer the ownership of the group to other group members.
    After the group ownership is transferred, all group members receive the onGroupInfoChanged callback, where the type of V2TIMGroupChangeInfo is V2TIM_GROUP_INFO_CHANGE_TYPE_OWNER and the value is the UserID of the new group owner.

    FAQs

    1. Can a live streaming group (AVChatRoom) continue to receive messages after it was disconnected and then reconnected?

    Yes, but since live streaming group (AVChatRoom) does not support storing message history in the cloud, it cannot pull the messages that were sent when it was disconnected.

    2. Why doesn’t the group receive notifications when a user joins or quits the group?

    Verify the group type:

    • Temporary meeting group (Meeting) does not support member change notifications.
    • Live streaming group (AVChatRoom) can receive up to 40 messages per second, therefore it prioritizes the receiving and sending of high-priority messages and discards messages with the lowest priority first once the frequency limit is exceeded.

    3. Why does the unread count of temporary meeting group (Meeting) remain at 0?

    Temporary meeting group (Meeting) and live streaming group (AVChatRoom) are designed for conference and live streaming scenarios respectively, and they do not support the unread count feature.