Starter Deal! First 3 month from only  $9.9 /month!
Starter Deal! First 3 month from only  $9.9 /month!
Grab It Now 
Chat
  • Web
    • TUIKit
      • Overview
      • Installaton
        • TUIKit
          • Vue
          • React
        • TUIChat Only
          • Vue
      • Features
        • Reactions
        • Read Receipt
        • Typing Status
        • User Online Status
      • Themes
        • Setting UI Styles
          • Web
          • Mobile
      • Customization
        • Customize Messages
      • Localization
    • SDK
      • Install Chat SDK
      • Initialize Chat SDK
      • Login and Logout
      • Client APIs
      • Message
        • Overview
        • Send a Message
        • Receive a Message
        • Historical Message
        • Forward Messages
        • Modify a Message
        • Delete Messages
        • Clear History Message
        • Recall a Message
        • Send an Online Message
        • Message Read Receipt
        • Query Messages
        • Targeted Group Message
        • Do not Notify
        • Key-Value Extensions
        • Translation
      • Conversation
        • Overview
        • Conversation List
        • Get Conversations
        • Unread Count
        • Pin Conversations
        • Delete Conversations
        • Mark
        • Conversation Group
      • Group
        • Overview
        • Group Management
        • Group Profile
        • Group Member Management
        • Group Member Profile
        • Custom Group Attribute
        • Group Counter
      • Community Topic
        • Community Management
      • User Profile and Relationship Chain
        • User Profile
        • User Status
        • Friend Management
        • Friend List
        • Block List
  • Android
    • Run Demo
    • UIKit
      • Overview
      • Getting Started
      • Installation
        • TUIKit
        • TUIChat Only
      • Features
        • Reactions
        • Read Receipt
        • User Online Status
        • Search Messages
      • Customization
        • Customize Messages
        • Customize Emojis and Stickers
      • Localization
    • SDK
      • Install Chat SDK
      • Initialize Chat SDK
      • Login and Logout
      • Message
        • Overview
        • Send a Message
        • Receive a Message
        • Retrieve Messages
        • Forward Messages
        • Modify a Message
        • Insert a Message
        • Delete Messages
        • Clear History Messages
        • Recall a Message
        • Send an Online Message
        • Message Read Receipt
        • Query Messages
        • Metions
        • Targeted Group Message
        • Do not Notify
        • Key-Value Extensions
        • Reactions
        • Translation
        • Pin Messages
      • Conversation
        • Overview
        • Conversation List
        • Get Conversations
        • Unread Count
        • Pin Conversations
        • Delete Conversations
        • Draft
        • Mark
        • Conversation Group
      • Group
        • Overview
        • Manage Group
        • Profile
        • Manage Members
        • Member Profile
        • Attribute
        • Counter
      • Community and Topic
        • Manage Community
        • Permission Group
      • User
        • User Profile
        • User Status
        • Manage Friends
        • Friend Group
        • Block Lists
      • Local Search
        • Search Messages
        • Search Friends
        • Search Groups
        • Search Group Members
      • Signaling
      • API Reference
        • Java
  • iOS and macOS
    • Run Demo
    • UIKit
      • Overview
      • Getting Started
      • Installation
        • TUIKit
        • TUIChat Only
      • Features
        • Reactions
        • Read Receipt
        • User Online Status
        • Search Messages
      • Customization
        • Customize Messages
        • Customize Emojis and Stickers
      • Localization
    • SDK
      • Installation
        • iOS
        • macOS
      • Initialize Chat SDK
      • Login and Logout
      • Message
        • Overview
        • Send a Message
        • Receive a Message
        • Retrieve Messages
        • Forward Messages
        • Modify a Message
        • Insert a Message
        • Delete Messages
        • Clear History Messages
        • Recall a Message
        • Send an Online Message
        • Message Read Receipt
        • Query Messages
        • Metions
        • Targeted Group Messages
        • Do not Notify
        • Key-Value Extensions
        • Reactions
        • Translation
        • Pin Messages
      • Conversation
        • Overview
        • Conversation List
        • Get Conversations
        • Unread Count
        • Pin Conversations
        • Delete Conversations
        • Draft
        • Mark
        • Conversation Group
      • Group
        • Overview
        • Manage Group
        • Profile
        • Manage Members
        • Member Profile
        • Attribute
        • Counter
      • Community and Topic
        • Manage Community
        • Permission Group
      • User
        • User Profile
        • User Status
        • Manage Friends
        • Friend Group
        • Block Lists
      • Local Search
        • Search Messages
        • Search Friends
        • Search Groups
        • Search Group Members
      • Signaling
      • API Reference
        • Swift
        • Objective-C
  • Windows
    • SDK
      • Install Chat SDK
      • Initialize Chat SDK
      • Login and Logout
      • Message
        • Overview
        • Send a Message
        • Receive a Message
        • Retrieve Messages
        • Forward Messages
        • Modify a Message
        • Insert a Message
        • Delete Messages
        • Clear History Messages
        • Recall a Message
        • Send an Online Message
        • Message Read Receipt
        • Query Messages
        • Metions
        • Targeted Group Messages
        • Do not Notify
        • Key-Value Extensions
        • Reactions
        • Translation
        • Pin Messages
      • Conversation
        • Overview
        • Conversation List
        • Get Conversations
        • Unread Count
        • Pin Conversations
        • Delete Conversations
        • Draft
        • Mark
        • Conversation Group
      • Group
        • Overview
        • Manage Group
        • Profile
        • Manage Members
        • Member Profile
        • Attribute
        • Counter
      • Community and Topic
        • Manage Community
        • Permission Group
      • User
        • User Profile
        • User Status
        • Manage Friends
        • Friend Group
        • Block Lists
      • Local Search
        • Search Messages
        • Search Friends
        • Search Groups
        • Search Group Members
      • Signaling
      • API Reference
        • C++
        • C
  • Flutter
    • Run Demo
    • UIKIT
      • Overview
      • Installation
        • integrated
      • Features
        • Local Search
        • Offline Push
        • Online Status
        • Typing Status
        • Message Read Receipt
        • Message Reactions
        • Internationalization
        • Adding Custom Messages
        • Emoji & Stickers
      • Customization
        • Modifying UI Themes
        • Setting UI Styles
    • SDK
      • Install Chat SDK
        • Install
      • Initialize Chat SDK
        • Initialize
      • Login And Logout
        • Login and Logout
      • Message
        • Message Overview
        • Sending Message
        • Receiving Message
        • Historical Message
        • Forwarding Message
        • Modifying Message
        • Message Inserting
        • Deleting Message
        • Clearing Messages
        • Recalling Message
        • Online Message
        • Read Receipt
        • Querying Message
        • Group @ Message
        • Targeted Group Message
        • Notification Muting
        • Message Extension
      • Conversation
        • Conversation Overview
        • Conversation List
        • Getting Conversation
        • Conversation Unread Count
        • Pinning Conversation to the Top
        • Deleting Conversation
        • Conversation Draft
        • Conversation Group
      • Group
        • Group Overview
        • Group Management
        • Group Profile
        • Group Member Management
        • Group Member Profile
        • Custom Group Attribute
      • User
        • User Profile
        • Friend Management
        • Friend List
        • Blocklist
      • Offline Push
        • Offline Push
      • Signaling
        • Signaling Management
      • Local Search
        • Searching for Message
        • Searching for Friend
        • Searching Group
        • Searching for Group Member
      • API Reference
        • Client APIs
  • React Native
    • Run Demo
    • SDK
      • SDK Integration
      • Initialization
      • Login and Logout
      • Message
        • Message Overview
        • Sending Message
        • Receiving Message
        • Historical Message
        • Forwarding Message
        • Modifying Message
        • Message Inserting
        • Deleting Message
        • Clearing Messages
        • Recalling Message
        • Online Message
        • Read Receipt
        • Querying Message
        • Group @ Message
        • Targeted Group Message
        • Notification Muting
        • Message Extension
      • Group
        • Overview
        • Group Management
        • Group Profile
        • Group Member Management
        • Group Member Profile
        • Custom Group Attribute
        • Community Management
      • User
        • User Profile
        • Friend Management
        • Friend List
        • Blocklist
      • Offline Push
        • Offline Push
      • Local Search
        • Searching for Message
        • Searching for Friend
        • Searching Group
        • Searching for Group Member
      • Signaling
        • Signaling Management
  • Unity(Game Solution)
    • Run Demo
    • SDK
      • SDK Integration
      • Initialization
      • Login and Logout
      • Message
        • Message Overview
        • Sending Message
        • Receiving Message
        • Historical Message
        • Forwarding Message
        • Modifying Message
        • Deleting Message
        • Clearing Messages
        • Recalling Message
        • Online Message
        • Read Receipt
        • Querying Message
        • Group @ Message
        • Targeted Group Message
        • Notification Muting
        • Message Extension
      • Conversation
        • Conversation Overview
        • Conversation List
        • Getting Conversation
        • Conversation Unread Count
        • Pinning Conversation to the Top
        • Deleting Conversation
        • Conversation Draft
        • Conversation Mark
        • Conversation Group
      • Group
        • Group Overview
        • Group Management
        • Group Profile
        • Group Member Management
        • Group Member Profile
        • Custom Group Attribute
        • Group Counter
      • User
        • User Profile
        • User Status
        • Friend Management
        • Friend List
        • Blocklist
  • Unreal Engine(Game Solution)
    • SDK
      • SDK Integration
  • Free Demos
  • Server APIs
    • Generating UserSig
    • RESTful APIs
      • RESTful API Overview
      • RESTful API List
      • Message Related
        • Send Message
          • Sending One-to-One Messages to One User
          • Sending One-to-One Messages to Multiple Users
          • Sending Ordinary Messages in a Group
          • Sending System Messages in a Group
          • Broadcast Message of Audio-Video Group
          • Importing One-to-One Messages
          • Importing Group Messages
        • Historical Message
          • Modifying Historical One-to-one Messages
          • Modifying Historical Group Messages
          • Pulling Historical One-to-one Messages
          • Pulling Historical Group Messages
        • Delete Message
          • Deleting Messages Sent by a Specified User
        • Withdraw Message
          • Recalling One-to-One Messages
          • Recalling Group Messages
        • Read Receipt
          • Marking One-to-One Messages as Read
          • Pulling Group Message Read Receipt Details
          • Pulling Read Receipts for Group Messages
        • Message Extension
          • Pulling the Message Extension of a One-to-One Message
          • Configuring Message Extension for a One-to-One Message
          • Pulling Message Extension of a Group Message
          • Configuring Message Extension for a Group Message
        • Pushing to All Users
          • API for Pushing to All Users
          • Pushing to All Users
          • Setting Application Attribute Names
          • Getting Application Attribute Names
          • Getting User Attributes
          • Setting User Attributes
          • Deleting User Attributes
          • Getting User Tags
          • Adding User Tags
          • Deleting User Tags
          • Deleting All Tags of a User
      • Session Related
        • Conversation List
          • Pulling a conversation list
        • Session Unread Count
          • Setting the Unread Message Count of a Member
          • Querying Unread One-to-One Message Count
        • Delete Session
          • Deleting a conversation
        • Session Grouping Tag
          • Creating Conversation Group Data
          • Updating Conversation Group Data
          • Deleting Conversation Group Data
          • Creating or Updating Conversation Mark Data
          • Searching for Conversation Group Marks
          • Pulling Conversation Group Mark Data
      • Group Related
        • Group Management
          • Getting All Groups in an App
          • Creating a Group
          • Disbanding a Group
          • Getting the Groups a User Has Joined
        • Group Information
          • Getting Group Profiles
          • Modifying the Profile of a Group
          • Importing a Group Profile
        • Group Member Management
          • Adding Group Members
          • Deleting Group Members
          • Banning Group Members
          • Unbanning Group Members
          • Bulk Muting and Unmuting
          • Getting the List of Muted Group Members
          • Changing Group Owner
          • Querying the Roles of Users in a Group
          • Importing Group Members
        • Group Member Information
          • Getting Group Member Profiles
          • Modifying the Profile of a Group Member
        • Group Custom Attributes
          • Getting Group Custom Attributes
          • Modifying Group Custom Attributes
          • Clearing Group Custom Attributes
          • Resetting Group Custom Attributes
          • Deleting Group Custom Attributes
        • Live Group Management
          • Getting the Number of Online Users in an Audio-Video Group
          • Getting the List of Online Members in Audio-Video Group
          • Setting Audio-Video Group Member Marks
          • Getting the List of Banned Group Members.
        • Community Management
          • Creating Topic
          • Deleting Topic
          • Getting Topic Profile
          • Modifying Topic Profile
          • Importing Topic Profiles
        • Group Counter
          • Getting Group Counters
          • Updating Group Counters
          • Deleting Group Counters
      • User Management
        • Account Management
          • Importing a Single Account
          • Importing Multiple Accounts
          • Deleting Accounts
          • Querying Accounts
        • User Information
          • Setting Profiles
          • Pulling Profiles
        • User Status
          • Invalidating Account Login States
          • Querying Account Online Status
        • Friend Management
          • Adding Friends
          • Importing Friends
          • Updating Friends
          • Deleting Friends
          • Deleting All Friends
          • Verifying Friends
          • Pulling Friends
          • Pulling Specified Friends
        • Friend Lists
          • Adding Lists
          • Deleting Lists
          • Pulling Lists
        • Blocklist
          • Blocklisting Users
          • Unblocklisting Users
          • Pulling a Blacklist
          • Verifying Users on a Blocklist
      • Global Mute Management
        • Setting Global Mute
        • Querying Global Mute
      • Operations Management
        • Pulling Operations Data
        • Downloading Recent Messages
        • Getting Server IP Addresses
      • Chatbots
        • Pulling Chatbot Accounts
        • Creating Chatbot Accounts
        • Deleting Chatbot Accounts
    • Webhooks
      • Webhook Overview
      • Webhook Command List
      • Operations Management Callbacks
        • API Overclocking Alarm Callbacks
      • Online Status Webhooks
        • Status Change Webhooks
      • Relationship Chain Webhooks
        • After a Profile Is Updated
        • Before a Friend Is Added
        • Before a Friend Request Is Responded
        • After a Friend Is Added
        • After a Friend Is Deleted
        • After a User Is Added to Blocklist
        • After a User Is Removed from Blocklist
      • One-to-One Message Webhooks
        • Before a One-to-One Message Is Sent
        • After a One-to-One Message Is Sent
        • After a One-to-One message Is Marked as Read
        • After A One-to-One Message Is Recalled
      • Group Webhooks
        • Before a Group Is Created
        • After a Group Is Created
        • Before Applying to Join a Group
        • Before Inviting a User to a Group
        • After a User Joins a Group
        • After a User Leaves a Group
        • Before Group Message Is Sent
        • After a Group Message Is Sent
        • After a Group Is Full
        • After a Group Is Disbanded
        • After Group Profile Is Modified
        • Callback After Recalling Group Messages
        • Webhook for Online and Offline Status of Audio-Video Group Members
        • Webhook for Exceptions When Group Messages Are Sent
        • Before a Topic Is Created
        • After a Topic Is Created
        • After a Topic Is Deleted
        • Topic Profile Change Webhook
        • Callback After Group Member Profile Changed
        • Callback After Group Attribute Changed
        • Callback After Read Receipt
        • Callback After the Group Owner Changed
      • Webhook Mutual Authentication Configuration Guide
        • Apache Mutual Authentication Configuration
        • Nginx Mutual Authentication Configuration
      • Chatbot webhooks
        • Chatbot Passthrough Message Callback
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes
Chat

Manage Group

Overview

The group management feature allows creating a group, joining a group, getting the joined groups, leaving a group, or disbanding a group through methods in the V2TIMGroupManager(Android) / V2TIMManager(Group)(iOS and macOS) core class.

Group Event Listener

In the group management feature as described below, the IM SDK will automatically trigger the group event notification callback, for example, when someone joins or leaves a group.
Call addGroupListener (Android / iOS and macOS / Windows) to add a group event listener.
Group events are defined in V2TIMGroupListener (Android / iOS and macOS / Windows), including group member notification, group lifecycle notification, group join request notification, and topic event listening callback.
To stop receiving group events, call removeGroupListener (Android / iOS and macOS / Windows) to remove the group event listener.
If you have configured a group event listener but don't receive events as expected, you can log in to the IM console to check or configure the group system notification as follows:



Caution
Audio-video groups don't support configuring the notifications of group member change and group profile change.
Sample code:
Android
iOS and macOS
Windows
V2TIMGroupListener groupListener = new V2TIMGroupListener() {
// Group member notification, group lifecycle notification, group join request notification, topic event listening callback, etc.
@Override
public void onMemberEnter(String groupID, List<V2TIMGroupMemberInfo> memberList) {
// A member joined the group. All the group members can receive the notification.
}
@Override
void onMemberLeave(String groupID, V2TIMGroupMemberInfo member) {
// A member left the group. All the group members can receive the notification.
}

@Override
public void onReceiveRESTCustomData(String groupID, byte[] customData) {
// Custom system notification sent by the server
}
};

V2TIMManager.getInstance().addGroupListener(groupListener);
[[V2TIMManager sharedInstance] addGroupListener:self];

// Group member notification, group lifecycle notification, group join request notification, topic event listening callback, etc.
- (void)onMemberEnter:(NSString *)groupID memberList:(NSArray<V2TIMGroupMemberInfo *>*)memberList {
// A member joined the group. All the group members can receive the notification.
}

- (void)onMemberLeave:(NSString *)groupID member:(V2TIMGroupMemberInfo *)member {
// A member left the group. All the group members can receive the notification.
}

- (void)onReceiveRESTCustomData:(NSString *)groupID data:(NSData *)data {
// Custom system notification sent by the server
}
class GroupListener final : public V2TIMGroupListener {
public:
GroupListener() = default;
~GroupListener() override = default;

// Group member notification, group lifecycle notification, group join request notification, topic event listening callback, etc.

void OnMemberEnter(const V2TIMString& groupID, const V2TIMGroupMemberInfoVector& memberList) override {
// A member joined the group. All the group members can receive the notification.
}

void OnMemberLeave(const V2TIMString& groupID, const V2TIMGroupMemberInfo& member) override {
// A member left the group. All the group members can receive the notification.
}

void OnReceiveRESTCustomData(const V2TIMString& groupID, const V2TIMBuffer& customData) override {
// Custom system notification sent by the server
}
};

// Add a group event listener. Keep `groupListener` valid before the listener is removed to ensure event callbacks are received.
GroupListener groupListener;
V2TIMManager::GetInstance()->AddGroupListener(&groupListener);

Creating a Group

Ordinary API

Call the createGroup ordinary API (Android / iOS and macOS / Windows) and specify parameters to create a group.
The createGroup parameters are as described below:
Parameter
Definition
Required
Description
groupType
Group type
Yes
For more information, see Group Types.
groupID
Group ID
No
If it is left empty, an ID will be automatically assigned after a group is created successfully.
It can be customized as instructed in Custom Group IDs.
groupName
Group name
Yes
It can contain up to 30 bytes.
If you have called addGroupListener to add a group event listener as instructed in Group Event Listener, onGroupCreated (Android / iOS and macOS / Windows) will be called back after a group is created successfully.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getInstance().createGroup(V2TIMManager.GROUP_TYPE_WORK, null, "groupA", new V2TIMValueCallback<String>() {
@Override
public void onSuccess(String s) {
// Group created successfully
}

@Override
public void onError(int code, String desc) {
// Failed to create the group
}
});
// Listen for the group creation notification
V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {
@Override
public void onGroupCreated(String groupID) {
// A group was created. `groupID` is the ID of the created group.
}
});
// Create a group
[[V2TIMManager sharedInstance] createGroup:GroupType_Work groupID:nil groupName:@"groupA" succ:^(NSString *groupID) {
// Group created successfully
} fail:^(int code, NSString *desc) {
// Failed to create the group
}];

// Listen for the group creation notification
[[V2TIMManager sharedInstance] addGroupListener:self];
- (void)onGroupCreated:(NSString *)groupID {
// A group was created. `groupID` is the ID of the created group.
}
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

auto callback = new ValueCallback<V2TIMString>{};
callback->SetCallback(
[=](const V2TIMString& string) {
// Group created successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to create the group
delete callback;
});

V2TIMManager::GetInstance()->CreateGroup("Work", {}, "groupA", callback);

// Listen for the group creation notification
class GroupListener final : public V2TIMGroupListener {
public:
GroupListener() = default;
~GroupListener() override = default;

void OnGroupCreated(const V2TIMString& groupID) override {
// A group was created. `groupID` is the ID of the created group.
}
// Other members …
};
// Add a group event listener. Keep `groupListener` valid before the listener is removed to ensure event callbacks are received.
GroupListener groupListener;
V2TIMManager::GetInstance()->AddGroupListener(&groupListener);

Advanced API

To initialize the group information such as group introduction, group profile photo, and existing group members when creating a group, call the createGroup advanced API (Android / iOS and macOS / Windows), and the groupID will be returned in the callback for successful creation.
Sample code:
Android
iOS and macOS
Windows
// Use the `createGroup` advanced API to create a work group
V2TIMGroupInfo v2TIMGroupInfo = new V2TIMGroupInfo();
v2TIMGroupInfo.setGroupName("testWork");
v2TIMGroupInfo.setGroupType("Work");
v2TIMGroupInfo.setIntroduction("this is a test Work group");

List<V2TIMCreateGroupMemberInfo> memberInfoList = new ArrayList<>();
V2TIMCreateGroupMemberInfo memberA = new V2TIMCreateGroupMemberInfo();
memberA.setUserID("vinson");
V2TIMCreateGroupMemberInfo memberB = new V2TIMCreateGroupMemberInfo();
memberB.setUserID("park");
memberInfoList.add(memberA);
memberInfoList.add(memberB);

V2TIMManager.getGroupManager().createGroup(
v2TIMGroupInfo, memberInfoList, new V2TIMValueCallback<String>() {
@Override
public void onError(int code, String desc) {
// Creation failed
}
@Override
public void onSuccess(String groupID) {
// Group created successfully
}
});
// Use the `createGroup` advanced API to create a work group
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
}];
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

// Use the `createGroup` advanced API to create a work group
V2TIMGroupInfo info;
info.groupType = "Work";
info.groupName = "testWork";
info.introduction = "this is a test Work group";

V2TIMCreateGroupMemberInfoVector memberInfoList;
V2TIMCreateGroupMemberInfo memberInfo1;
memberInfo1.userID = "vinson";
memberInfoList.PushBack(memberInfo1);
V2TIMCreateGroupMemberInfo memberInfo2;
memberInfo2.userID = "park";
memberInfoList.PushBack(memberInfo2);

auto callback = new ValueCallback<V2TIMString>{};
callback->SetCallback(
[=](const V2TIMString& string) {
// Group created successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Creation failed
delete callback;
});

V2TIMManager::GetInstance()->GetGroupManager()->CreateGroup(info, memberInfoList, callback);

Joining a Group

The method for joining a group may vary by group type as follows:
Type
Method for Joining a Group
Work group (Work)
By invitation
Public group (Public)
On request from the user and on approval from the group owner or admin
Meeting group (Meeting)
Free to join
Community (Community)
Free to join
Audio-video group (AVChatRoom)
Free to join
The following describes how to join the groups in an easy-to-hard sequence.
Caution
You need to call addGroupListener to add a group event listener in advance as instructed in Group Event Listener to receive the following group events.

Free to join a group

Meeting groups (Meeting), audio-video groups (AVChatRoom), and communities are mainly used for free interaction scenarios, such as online meeting and live show. The process of joining such groups is the simplest:
1. The user calls joinGroup (Android / iOS and macOS / Windows) to join the group.
2. After the user has successfully joined the group, all the group members (including the user) will receive the onMemberEnter callback (Android / iOS and macOS / Windows).
Note:
Work group does not support free group joining a group by default, you can modify the groupAddOpt field of V2TIMGroupInfo by calling setGroupInfo (Android / iOS & Mac / Windows) to enable free group joining.
Sample code:
Android
iOS and macOS
Windows
// Join a group
V2TIMManager.getInstance().joinGroup("groupA", "it's me!", new V2TIMCallback() {
@Override
public void onSuccess() {
// Joined the group successfully
}

@Override
public void onError(int code, String desc) {
// Failed to join the group
}
});

// Listen for the group join event
V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {
@Override
public void onMemberEnter(String groupID, List<V2TIMGroupMemberInfo> memberList) {
// A user joined the group.
}
});

// Join a group
[[V2TIMManager sharedInstance] joinGroup:@"groupA" msg:@"it's me!" succ:^{
// Joined the group successfully
} fail:^(int code, NSString *desc) {
// Failed to join the group
}];

// Listen for the group join event
[[V2TIMManager sharedInstance] addGroupListener:self];
- (void)onMemberEnter:(NSString *)groupID memberList:(NSArray<V2TIMGroupMemberInfo *>*)memberList {
// A user joined the group.
}
class Callback final : public V2TIMCallback {
public:
using SuccessCallback = std::function<void()>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

Callback() = default;
~Callback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess() override {
if (success_callback_) {
success_callback_();
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

auto callback = new Callback{};
callback->SetCallback(
[=]() {
// Joined the group successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to join the group
delete callback;
});

V2TIMManager::GetInstance()->JoinGroup("groupA", "it's me!", callback);

// Listen for the group join event
class GroupListener final : public V2TIMGroupListener {
public:
GroupListener() = default;
~GroupListener() override = default;

void OnMemberEnter(const V2TIMString& groupID, const V2TIMGroupMemberInfoVector& memberList) override {
// A user joined the group.
}
// Other members …
};
// Add a group event listener. Keep `groupListener` valid before the listener is removed to ensure event callbacks are received.
GroupListener groupListener;
V2TIMManager::GetInstance()->AddGroupListener(&groupListener);

Joining a group by invitation

Work groups (Work) are suitable for communication in work environments. The interaction pattern is designed to disable proactive group joining and only allow users to be invited to join the group by group members. The steps to join a group are as follows:
1. A group member calls inviteUserToGroup (Android / iOS and macOS / Windows) to invite a user to the group.
2. All the group members (including the inviter) receive the onMemberInvited callback (Android / iOS and macOS / Windows), which can contain some UI tips.
Note:
1. Since v7.1, other group types except work group (Work) do not support joining a group by invitation by default, you can modify the groupApproveOpt field of V2TIMGroupInfo by calling setGroupInfo (Android / iOS & Mac / Windows) to open joining a group by invitation.
2. AVChatRoom group, community, and topic do not allow joining a group by invitation by default, and do not support modification.
Sample code:
Android
iOS and macOS
Windows
// Invite the `userA` user to join the `groupA` group
List<String> userIDList = new ArrayList<>();
userIDList.add("userA");
V2TIMManager.getGroupManager().inviteUserToGroup("groupA", userIDList, new V2TIMValueCallback<List<V2TIMGroupMemberOperationResult>>() {
@Override
public void onSuccess(List<V2TIMGroupMemberOperationResult> v2TIMGroupMemberOperationResults) {
// Invited the user to the group successfully
}

@Override
public void onError(int code, String desc) {
// Failed to invite the user to the group
}
});

// Listen for the group invitation event
V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {
@Override
public void onMemberInvited(String groupID, V2TIMGroupMemberInfo opUser, List<V2TIMGroupMemberInfo> memberList) {
// A user was invited to the group. This callback can contain some UI tips.
}
});
// Invite the `userA` user to join the `groupA` group
[[V2TIMManager sharedInstance] inviteUserToGroup:@"groupA" userList:@[@"userA"] succ:^(NSArray<V2TIMGroupMemberOperationResult *> *resultList) {
// Invited the user to the group successfully
} fail:^(int code, NSString *desc) {
// Failed to invite the user to the group
}];

// Listen for the group invitation event
[[V2TIMManager sharedInstance] addGroupListener:self];
- (void)onMemberInvited:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser memberList:(NSArray<V2TIMGroupMemberInfo *>*)memberList {
// This callback can contain some UI tips.
}
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

// Invite the `userA` user to join the `groupA` group
V2TIMStringVector userList;
userList.PushBack("userA");

auto callback = new ValueCallback<V2TIMGroupMemberOperationResultVector>{};
callback->SetCallback(
[=](const V2TIMGroupMemberOperationResultVector& groupMemberOperationResultList) {
// Invited the user to the group successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to invite the user to the group
delete callback;
});

V2TIMManager::GetInstance()->GetGroupManager()->InviteUserToGroup("groupA", userList, callback);

// Listen for the group invitation event
class GroupListener final : public V2TIMGroupListener {
public:
GroupListener() = default;
~GroupListener() override = default;

void OnMemberInvited(const V2TIMString& groupID, const V2TIMGroupMemberInfo& opUser,
const V2TIMGroupMemberInfoVector& memberList) override {
// A user was invited to the group. This callback can contain some UI tips.
}
// Other members …
};
// Add a group event listener. Keep `groupListener` valid before the listener is removed to ensure event callbacks are received.
GroupListener groupListener;
V2TIMManager::GetInstance()->AddGroupListener(&groupListener);

Joining a group on request and on approval

A public group (Public) is similar to the interest group and clan group of QQ. Anyone can join it on request and on approval from the group owner or admin.
The steps to join a group on request and on approval are as follows:


Description of process:
1. The user calls joinGroup (Android / iOS and macOS / Windows) to request to join the group.
2. The group owner or admin receives the onReceiveJoinApplication group join request notification (Android / iOS and macOS / Windows) and calls getGroupApplicationList (Android / iOS and macOS / Windows) to get the group join request list.
3. The group owner or admin traverses the group join request list and calls acceptGroupApplication (Android / iOS and macOS / Windows) to approve a request or refuseGroupApplication (Android / iOS and macOS / Windows) to reject it.
4. After the request to join the group is approved or rejected, the user will receive the onApplicationProcessed callback (Android / iOS and macOS / Windows). Here, if isAgreeJoin is true/YES, the request is approved; otherwise, it is rejected.
5. On approval, all the group members (including the user) will receive the onMemberEnter callback (Android / iOS and macOS / Windows), notifying the group members that someone joined the group.
Sample code:
Android
iOS and macOS
Windows
// ******Group owner******//
// 1. The group owner changes the group join option to approval required.
V2TIMGroupInfo groupInfo = new V2TIMGroupInfo();
groupInfo.setGroupID("groupB");
groupInfo.setGroupAddOpt(V2TIMGroupInfo.V2TIM_GROUP_ADD_AUTH);
V2TIMManager.getGroupManager().setGroupInfo(groupInfo, new V2TIMCallback() {
@Override
public void onSuccess() {
// Changed the group join option successfully
}

@Override
public void onError(int code, String desc) {
// Failed to change the group join option
}
});

// 2. The group owner listens for and processes requests to join the group.
V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {
@Override
public void onReceiveJoinApplication(String groupID, V2TIMGroupMemberInfo member, String opReason) {
V2TIMManager.getGroupManager().getGroupApplicationList(new V2TIMValueCallback<V2TIMGroupApplicationResult>() {
@Override
public void onSuccess(V2TIMGroupApplicationResult v2TIMGroupApplicationResult) {
List<V2TIMGroupApplication> groupApplicationList = v2TIMGroupApplicationResult.getGroupApplicationList();
for (V2TIMGroupApplication application : groupApplicationList) {
if (application.getGroupID().equals(groupID) && application.getFromUser().equals(member.getUserID())) {
// Approve group join
if (agree) {
// Approve the group join request
V2TIMManager.getGroupManager().acceptGroupApplication(application, "agree", new V2TIMCallback() {
@Override
public void onSuccess() {
// Approved the group join request successfully
}

@Override
public void onError(int code, String desc) {
// Failed to approve the group join request
}
});
} else {
// Reject the group join request
V2TIMManager.getGroupManager().refuseGroupApplication(application, "not agree", new V2TIMCallback() {
@Override
public void onSuccess() {
// Rejected the group join request successfully
}

@Override
public void onError(int code, String desc) {
// Failed to reject the group join request
}
});
}
return;
}
}

V2TIMManager.getGroupManager().setGroupApplicationRead(new V2TIMCallback() {
@Override
public void onSuccess() {
// Marked the group join request list as read successfully
}

@Override
public void onError(int code, String desc) {
// Failed to mark the group join request list as read
}
});
}

@Override
public void onError(int code, String desc) {
// Failed to obtain the group join request list
}
});
}
});

// ******User******//
// 1. The user requests to join the group.
V2TIMManager.getInstance().joinGroup("groupB", "it's me!", new V2TIMCallback() {
@Override
public void onSuccess() {
// Joined the group successfully
}

@Override
public void onError(int code, String desc) {
// Failed to join the group
}
});
// 2. The user listens for the request review result.
V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {
@Override
public void onApplicationProcessed(String groupID, V2TIMGroupMemberInfo opUser, boolean isAgreeJoin,
String opReason) {
// The request to join the group is processed.
}

@Override
public void onMemberEnter(String groupID, List<V2TIMGroupMemberInfo> memberList) {
// This callback will be received if the group join request is approved.
}
});
// ******Group owner******//
// 1. The group owner changes the group join option to approval required.
V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
info.groupID = @"groupA";
info.groupAddOpt = V2TIM_GROUP_ADD_AUTH;
[[V2TIMManager sharedInstance] setGroupInfo:info succ:^{
// Changed the group join option successfully
} fail:^(int code, NSString *desc) {
// Changed the group join option successfully
}];

// 2. The group owner listens for and processes requests to join the group.
[[V2TIMManager sharedInstance] addGroupListener:self];
- (void)onReceiveJoinApplication:(NSString *)groupID member:(V2TIMGroupMemberInfo *)member opReason:(NSString *)opReason {
[[V2TIMManager sharedInstance] getGroupApplicationList:^(V2TIMGroupApplicationResult *result) {
for (V2TIMGroupApplication *application in result.applicationList) {
if ([application.groupID isEqualToString:groupID] && [application.fromUser isEqualToString:member.userID]) {
// Approve group join
[[V2TIMManager sharedInstance] acceptGroupApplication:application reason:@"agree" succ:^{
// Approved the group join request successfully
} fail:^(int code, NSString *desc) {
// Failed to approve the group join request
}];

// Reject group join
[[V2TIMManager sharedInstance] refuseGroupApplication:application reason:@"refuse" succ:^{
// Rejected the group join request successfully
} fail:^(int code, NSString *desc) {
// Failed to reject the group join request
}];

// Mark the request as read
[[V2TIMManager sharedInstance] setGroupApplicationRead:^{
// Marked the group join request list as read successfully
} fail:^(int code, NSString *desc) {
// Failed to mark the group join request list as read
}];
}
}
} fail:^(int code, NSString *desc) {
// Failed to obtain the group join request list
}];
}

// ******Request******//
// 1. The user requests to join the group.
[[V2TIMManager sharedInstance] joinGroup:@"groupA" msg:@"it's me!" succ:^{
// Joined the group successfully
} fail:^(int code, NSString *desc) {
// Failed to join the group
}];

// 2. The user listens for the request review result.
[[V2TIMManager sharedInstance] addGroupListener:self];
- (void)onApplicationProcessed:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser opResult:(BOOL)isAgreeJoin opReason:(NSString *)opReason {
// The request to join the group is processed.
}
- (void)onMemberEnter:(NSString *)groupID memberList:(NSArray<V2TIMGroupMemberInfo *>*)memberList; {
// This callback will be received if the group join request is approved.
}
class Callback final : public V2TIMCallback {
public:
using SuccessCallback = std::function<void()>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

Callback() = default;
~Callback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess() override {
if (success_callback_) {
success_callback_();
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

////////////////////////////////////////////////// Group owner //////////////////////////////////////////////////

// 1. The group owner changes the group join option to approval required.
V2TIMGroupInfo info;
info.groupID = "groupB";
info.groupAddOpt = V2TIMGroupAddOpt::V2TIM_GROUP_ADD_AUTH;
info.modifyFlag = V2TIMGroupInfoModifyFlag::V2TIM_GROUP_INFO_MODIFY_FLAG_GROUP_ADD_OPTION;
auto callback = new Callback;
callback->SetCallback(
[=]() {
// Changed the group join option successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to change the group join option
delete callback;
});
V2TIMManager::GetInstance()->GetGroupManager()->SetGroupInfo(info, callback);

// 2. The group owner listens for and processes requests to join the group.
class GroupListener final : public V2TIMGroupListener {
public:
GroupListener() = default;
~GroupListener() override = default;

void OnReceiveJoinApplication(const V2TIMString& groupID, const V2TIMGroupMemberInfo& member,
const V2TIMString& opReason) override {
auto callback = new ValueCallback<V2TIMGroupApplicationResult>{};
callback->SetCallback(
[=](const V2TIMGroupApplicationResult& groupApplicationResult) {
const V2TIMGroupApplicationVector& groupApplicationList =
groupApplicationResult.applicationList;
for (size_t i = 0; i < groupApplicationList.Size(); ++i) {
const V2TIMGroupApplication& application = groupApplicationList[i];
if (application.groupID == groupID && application.fromUser == member.userID) {
if (...) { // Approve group join
auto callback = new Callback;
callback->SetCallback(
[=]() {
// Approved the group join request successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to approve the group join request
delete callback;
});
V2TIMManager::GetInstance()->GetGroupManager()->AcceptGroupApplication(
application, "agree", callback);
} else { // Reject group join
auto callback = new Callback;
callback->SetCallback(
[=]() {
// Rejected the group join request successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to reject the group join request
delete callback;
});
V2TIMManager::GetInstance()->GetGroupManager()->RefuseGroupApplication(
application, "refuse", callback);
}
break;
}
}

auto callback = new Callback;
callback->SetCallback(
[=]() {
// Marked the group join request list as read successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to mark the group join request list as read
delete callback;
});
V2TIMManager::GetInstance()->GetGroupManager()->SetGroupApplicationRead(callback);

delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to obtain the group join request list
delete callback;
});

V2TIMManager::GetInstance()->GetGroupManager()->GetGroupApplicationList(callback);
}
// Other members …
};
// Add a group event listener. Keep `groupListener` valid before the listener is removed to ensure event callbacks are received.
GroupListener groupListener;
V2TIMManager::GetInstance()->AddGroupListener(&groupListener);

////////////////////////////////////////////////// User //////////////////////////////////////////////////

// 1. The user requests to join the group.
auto callback = new Callback{};
callback->SetCallback(
[=]() {
// Joined the group successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to join the group
delete callback;
});
V2TIMManager::GetInstance()->JoinGroup("groupB", "it's me!", callback);

// 2. The user listens for the request review result.
class GroupListener final : public V2TIMGroupListener {
public:
GroupListener() = default;
~GroupListener() override = default;

void OnApplicationProcessed(const V2TIMString& groupID, const V2TIMGroupMemberInfo& opUser,
bool isAgreeJoin, const V2TIMString& opReason) override {
// The request to join the group is processed.
}
void OnMemberEnter(const V2TIMString& groupID, const V2TIMGroupMemberInfoVector& memberList) override {
// This callback will be received if the group join request is approved.
}
// Other members …
};
// Add a group event listener. Keep `groupListener` valid before the listener is removed to ensure event callbacks are received.
GroupListener groupListener;
V2TIMManager::GetInstance()->AddGroupListener(&groupListener);
The group owner or admin can also call the setGroupInfo API (Android / iOS and macOS / Windows) to change the group join option (groupAddOpt) and approval option (groupApproveOpt) to "no group join allowed" or "no approval required".
V2TIMGroupAddOpt has the following options:
Group Join Option
Description
V2TIM_GROUP_ADD_FORBID
No users can join the group.
V2TIM_GROUP_ADD_AUTH
Approval from the group owner or admin is required to join the group (default value).
V2TIM_GROUP_ADD_ANY
Any user can join the group without approval.


Getting the Joined Groups

Call getJoinedGroupList (Android / iOS and macOS / Windows) to get the list of joined work groups (Work), public groups (Public), meeting groups (Meeting), and communities (Community, which don't support the topic feature). Audio-video groups (AVChatRoom) and communities (Community, which support the topic feature) are not included in this list.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getGroupManager().getJoinedGroupList(new V2TIMValueCallback<List<V2TIMGroupInfo>>() {
@Override
public void onSuccess(List<V2TIMGroupInfo> v2TIMGroupInfos) {
// Obtained the list of joined groups successfully
}

@Override
public void onError(int code, String desc) {
// Failed to obtain the list of joined groups
}
});
[[V2TIMManager sharedInstance] getJoinedGroupList:^(NSArray<V2TIMGroupInfo *> *groupList) {
// Obtained the list of joined groups successfully
} fail:^(int code, NSString *desc) {
// Failed to obtain the list of joined groups
}];
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

auto callback = new ValueCallback<V2TIMGroupInfoVector>{};
callback->SetCallback(
[=](const V2TIMGroupInfoVector& groupInfoList) {
// Obtained the list of joined groups successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to obtain the list of joined groups
delete callback;
});

V2TIMManager::GetInstance()->GetGroupManager()->GetJoinedGroupList(callback);

Leaving a Group

Call quitGroup (Android / iOS and macOS / Windows) to leave a group. The member who left the group will receive the onQuitFromGroup callback (Android / iOS and macOS / Windows). Other group members will receive the onMemberLeave callback (Android / iOS and macOS / Windows).
Caution
The group owner cannot leave a public group (Public), meeting group (Meeting), community, or audio-video group (AVChatRoom) and can only disband it.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getInstance().quitGroup("groupA", new V2TIMCallback() {
@Override
public void onSuccess() {
// Left the group successfully
}

@Override
public void onError(int code, String desc) {
// Failed to leave the group
}
});

V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {
@Override
public void onMemberLeave(String groupID, V2TIMGroupMemberInfo member) {
// A group member left the group.
}
});
[[V2TIMManager sharedInstance] quitGroup:@"groupA" succ:^{
// Left the group successfully
} fail:^(int code, NSString *desc) {
// Failed to leave the group