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 Community

Feature Description

A community group is a large group of people brought together by common topics, and multiple topics can be created under the same community group based on different interests. Communities are used to manage group members. All topics under the same community are shared among members, who can send and receive messages within each topic independently.
Community and topic management APIs are in the V2TIMGroupManager(Android) / V2TIMManager(Group)(iOS and macOS) core class.
APIs related to messages in topics are in the V2TIMMessageManager(Android) / V2TIMManager(Message)(iOS and Mac) core class.
Note
This feature is supported by v6.2.2363 or later. To use it, you need to purchase the Premium edition, go to the console, choose Feature Configuration > Group configuration > Group feature configuration > Community, and enable the community feature.

Community Group Management

Creating a community group

You need to perform two steps to create a community group that supports topics:
1. Create the V2TIMGroupInfo object (Android / iOS and macOS / Windows) and set groupType to Community and isSupportTopic to true/YES.
2. Call the createGroup (Android / iOS & Mac / Windows) API to create a group.
Sample code:
Android
iOS and macOS
Windows
V2TIMGroupInfo v2TIMGroupInfo = new V2TIMGroupInfo();
v2TIMGroupInfo.setGroupName("This is a Community");
v2TIMGroupInfo.setGroupType(V2TIMManager.GROUP_TYPE_COMMUNITY);
v2TIMGroupInfo.setSupportTopic(true);
V2TIMManager.getGroupManager().createGroup(v2TIMGroupInfo, null, new V2TIMValueCallback<String>() {
@Override
public void onSuccess(String groupID) {
// Community group created successfully
}

@Override
public void onError(int code, String desc) {
// Creation failed
}
});
V2TIMGroupInfo *groupInfo = [[V2TIMGroupInfo alloc] init];;
groupInfo.groupName = @"This is a Community";
groupInfo.groupType = GroupType_Community;
groupInfo.isSupportTopic = YES;
[[V2TIMManager sharedInstance] createGroup:groupInfo memberList:nil succ:^(NSString *groupID) {
// Community group created successfully
} fail:^(int code, NSString *desc) {
// Creation failed
}];
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_;
};

V2TIMGroupInfo info;
info.groupType = "Community";
info.groupName = "This is a Community";
info.isSupportTopic = true;

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

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

Getting the list of community groups joined

You can call the getJoinedCommunityList(Android / iOS & Mac / Windows) API to get the list of topic supporting communities that you have joined.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getGroupManager().getJoinedCommunityList(new V2TIMValueCallback<List<V2TIMGroupInfo>>() {
@Override
public void onSuccess(List<V2TIMGroupInfo> v2TIMGroupInfos) {
// Community group list got successfully
}
@Override
public void onError(int code, String desc) {
// Failed to get the community group list
}
});

[[V2TIMManager sharedInstance] getJoinedCommunityList:^(NSArray<V2TIMGroupInfo *> *groupList) {
// Community group list got successfully
} fail:^(int code, NSString *desc) {
// Failed to get the community group list
}];
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) {
// Community group list obtained successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to get the community group list
delete callback;
});

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

Other management APIs

Other features can be used in the same way as an ordinary group feature and involve the following APIs:
Category
Feature
API
Community group management
joinGroup (Android / iOS and macOS / Windows)
quitGroup (Android / iOS and macOS / Windows)
dismissGroup (Android / iOS and macOS / Windows)
getGroupsInfo (Android / iOS and macOS / Windows)
setGroupInfo (Android / iOS and macOS / Windows)
Community group member management
getGroupMemberList (Android / iOS and macOS / Windows)
getGroupMembersInfo (Android / iOS and macOS / Windows)
setGroupMemberInfo (Android / iOS and macOS / Windows)
kickGroupMember (Android / iOS and macOS / Windows)


Topic Management

Multiple topics can be created under the same community group. All the topics are shared among group members, who can send and receive messages within each topic independently.
Note
To use the feature, you need to go to the console, choose Feature Configuration > Group configuration > Group feature configuration > Community, enable the community feature and then enable the topic feature.

Creating a topic

You need to perform two steps to create a topic:
1. Create the V2TIMTopicInfo object (Android / iOS and macOS / Windows).
2. Call the createTopicInCommunity (Android / iOS and Mac / Windows) API to create a topic.
Sample code:
Android
iOS and macOS
Windows
V2TIMTopicInfo topicInfo = new V2TIMTopicInfo();
topicInfo.setTopicName(topicName);
topicInfo.setTopicFaceUrl(topicFaceUrl);
topicInfo.setIntroduction(topicIntroduction);
topicInfo.setNotification(topicNotification);
topicInfo.setCustomString(topicCustomString);

// Set `groupID` to the ID of a community group that supports topics
V2TIMManager.getGroupManager().createTopicInCommunity(groupID, topicInfo, new V2TIMValueCallback<String>() {
@Override
public void onSuccess(String topicID) {
// Topic created successfully
}

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

V2TIMTopicInfo *topicInfo = [[V2TIMTopicInfo alloc] init];
topicInfo.topicName = @"topicName";
topicInfo.topicFaceURL = @"topicFaceUrl";
topicInfo.introduction = @"topicIntroduction";
topicInfo.notification = @"topicNotification";
topicInfo.customString = @"topicCustomString";

// Set `groupID` to the ID of a community group that supports topics
[[V2TIMManager sharedInstance] createTopicInCommunity:@"groupID" topicInfo:topicInfo succ:^(NSString *topicID) {
// Topic created successfully
} fail:^(int code, NSString *desc) {
// Failed to create the topic
}];
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_;
};

V2TIMTopicInfo topicInfo;
topicInfo.topicID = "topicID";
topicInfo.topicName = "topicName";
topicInfo.topicFaceURL = "topicFaceURL";
topicInfo.introduction = "introduction";
topicInfo.notification = "notification";

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

// Set `groupID` to the ID of a community group that supports topics
V2TIMManager::GetInstance()->GetGroupManager()->CreateTopicInCommunity("groupID", topicInfo, callback);

Deleting a topic

You can call the deleteTopicFromCommunity(Android / iOS & Mac / Windows) API to delete a topic.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getGroupManager().deleteTopicFromCommunity(groupID, topicIDList, new V2TIMValueCallback<List<V2TIMTopicOperationResult>>() {
@Override
public void onSuccess(List<V2TIMTopicOperationResult> v2TIMTopicOperationResults) {
// Topic deleted successfully
}

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

[[V2TIMManager sharedInstance] deleteTopicFromCommunity:@"groupID" topicIDList:@[@"topic1", @"topic2"] succ:^(NSMutableArray<V2TIMTopicOperationResult *> *resultList) {
// Topic deleted successfully
} fail:^(int code, NSString *desc) {
// Failed to delete the topic
}];
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_;
};

V2TIMStringVector topicIDList;
topicIDList.PushBack("topic1");
topicIDList.PushBack("topic2");

auto callback = new ValueCallback<V2TIMTopicOperationResultVector>{};
callback->SetCallback(
[=](const V2TIMTopicOperationResultVector& topicOperationResultList) {
// Topic deleted successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to delete the topic
delete callback;
});

V2TIMManager::GetInstance()->GetGroupManager()->DeleteTopicFromCommunity("groupID", topicIDList, callback);

Modifying topic information

You need to perform two steps to modify the information of a topic:
1. Create the V2TIMTopicInfo object (Android / iOS and macOS / Windows) and set the fields to be modified.
2. Call the setTopicInfo (Android / iOS and Mac / Windows) API to modify topic information.
Sample code:
Android
iOS and macOS
Windows
V2TIMTopicInfo topicInfo = new V2TIMTopicInfo();
topicInfo.setTopicID(topicID);
topicInfo.setTopicName(topicName);
topicInfo.setTopicFaceUrl(topicFaceUrl);
topicInfo.setIntroduction(topicIntroduction);
topicInfo.setNotification(topicNotification);
topicInfo.setCustomString(topicCustomString);
topicInfo.setDraft(topicDraft);
topicInfo.setAllMute(false);
V2TIMManager.getGroupManager().setTopicInfo(topicInfo, new V2TIMCallback() {
@Override
public void onSuccess() {
// Topic information modified successfully
}

@Override
public void onError(int code, String desc) {
// Failed to modify the topic information
}
});

V2TIMTopicInfo *topicInfo = [[V2TIMTopicInfo alloc] init];
topicInfo.topicID = @"topicID";
topicInfo.topicName = @"topicName";
topicInfo.topicFaceURL = @"topicFaceUrl";
topicInfo.introduction = @"topicIntroduction";
topicInfo.notification = @"topicNotification";
topicInfo.customString = @"topicCustomString";
topicInfo.draftText = @"topicDraft";
topicInfo.isAllMuted = NO;
[[V2TIMManager sharedInstance] setTopicInfo:topicInfo succ:^{
// Topic information modified successfully
} fail:^(int code, NSString *desc) {
// Failed to modify the topic information
}];
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_;
};

V2TIMTopicInfo topicInfo;
topicInfo.topicID = "topicID";
topicInfo.topicName = "topicName";
topicInfo.notification = "topicFaceURL";
topicInfo.introduction = "introduction";
topicInfo.topicFaceURL = "notification";
topicInfo.customString = "customString";
topicInfo.modifyFlag = V2TIMGroupInfoModifyFlag::V2TIM_GROUP_INFO_MODIFY_FLAG_GROUP_NAME |
V2TIMGroupInfoModifyFlag::V2TIM_GROUP_INFO_MODIFY_FLAG_NOTIFICATION |
V2TIMGroupInfoModifyFlag::V2TIM_GROUP_INFO_MODIFY_FLAG_INTRODUCTION |
V2TIMGroupInfoModifyFlag::V2TIM_GROUP_INFO_MODIFY_FLAG_FACE_URL |
V2TIMGroupInfoModifyFlag::V2TIM_TOPIC_INFO_MODIFY_FLAG_CUSTOM_STRING;

auto callback = new Callback;
callback->SetCallback(
[=]() {
// Topic information modified successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to modify the topic information
delete callback;
});

V2TIMManager::GetInstance()->GetGroupManager()->SetTopicInfo(topicInfo, callback);
For how to modify other information of a topic, see Muting Member and Changing Topic Message Receiving Option.

Getting the topic list

You can call the getTopicInfoList (Android / iOS and Mac / Windows) API to get the topic list.
If topicIDList is empty, the list of all topics of the community group will be got.
If topicIDList is the ID of specified topics, the list of the specified topics will be got.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getGroupManager().getTopicInfoList(groupID, topicIDList, new V2TIMValueCallback<List<V2TIMTopicInfoResult>>() {
@Override
public void onSuccess(List<V2TIMTopicInfoResult> v2TIMTopicInfoResults) {
// Topic list obtained successfully
}

@Override
public void onError(int code, String desc) {
// Failed to obtain the topic list
}
});
[[V2TIMManager sharedInstance] getTopicInfoList:@"groupID" topicIDList:@[@"topic1", @"topic2"] succ:^(NSMutableArray<V2TIMTopicInfoResult *> *resultList) {
// Topic list obtained successfully
} fail:^(int code, NSString *desc) {
// Failed to obtain the topic list
}];
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_;
};

V2TIMStringVector topicIDList;
topicIDList.PushBack("topic1");
topicIDList.PushBack("topic2");

auto callback = new ValueCallback<V2TIMTopicInfoResultVector>{};
callback->SetCallback(
[=](const V2TIMTopicInfoResultVector& topicInfoResultList) {
// Topic list obtained successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to obtain the topic list
delete callback;
});

V2TIMManager::GetInstance()->GetGroupManager()->GetTopicInfoList("groupID", topicIDList, callback);

Topic group

The community-group-topic hierarchy is implemented as follows: The customInfo (Android / iOS and macOS / Windows) in the community profile defines a field to store the topic group list of the community. The customString field (Android / iOS and macOS / Windows) in the topic profile stores the topic group.
When a community is loaded, the customInfo field for the topic group list in the community (group) profile is used to display the group list.
When the topic list of a community is loaded, the customString in the topic profile is used to get the group name for assignment.
Note
You can customize the key value of the customInfo field for the topic group list of the community (group). The following sample code names it topic_category.

Configuring the group list for the community

You just need to modify the customInfo in groupInfo. Here is a Map, and the key value is the name of the field for the topic group list you defined. Sample code:
Android
iOS and macOS
Windows
List<String> categoryList = new ArrayList<>();
categoryList.add("Group 1");
categoryList.add("Group 2");
byte[] categoriesByteArray = gson.toJson(categoryList).getBytes();

Map<String, byte[]> customMap = new HashMap<>();
// You need to configure the custom group field `topic_category` in the console first.
customMap.put("topic_category", categoriesByteArray);

V2TIMGroupInfo modifyInfo = new V2TIMGroupInfo();
modifyInfo.setGroupID(groupID);
modifyInfo.setCustomInfo(customMap);
V2TIMManager.getGroupManager().setGroupInfo(modifyInfo, new V2TIMCallback() {
@Override
public void onSuccess() {
// Modified the group profile successfully
}

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

NSArray *categoryList = @[@"Group 1", @"Group 2"];
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:categoryList
options:NSJSONWritingPrettyPrinted
error:&error];
if ([data length] > 0 && error == nil) {
// You need to configure the custom group field `topic_category` in the console first.
NSDictionary *customInfo = @{@"topic_category": data};

V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
info.groupID = @"Group ID of the group to be modified";
info.customInfo = customInfo;
[[V2TIMManager sharedInstance] setGroupInfo:info
succ:^{
// Modified the group profile successfully
} fail:^(int code, NSString *desc) {
// Failed to modify the group profile
}];
}
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_;
};

V2TIMGroupInfo info;
info.groupID = "groupA";

V2TIMCustomInfo customInfo;
std::string str{u8"[\"Group 1\", \"Group 2\"]"};
// You need to configure the custom group field `topic_category` in the console first.
customInfo.Insert("topic_category", {reinterpret_cast<const uint8_t*>(str.data()), str.size()});
info.modifyFlag = V2TIMGroupInfoModifyFlag::V2TIM_GROUP_INFO_MODIFY_FLAG_CUSTOM_INFO;

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

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

Getting the list of groups in the community

Sample code:
Android
iOS and macOS
Windows
String groupID = "group1";
List<String> groupIDList = new ArrayList<>();
groupIDList.add(groupID);
V2TIMManager.getGroupManager().getGroupsInfo(groupIDList, new V2TIMValueCallback<List<V2TIMGroupInfoResult>>() {
@Override
public void onSuccess(List<V2TIMGroupInfoResult> v2TIMGroupInfos) {
if (v2TIMGroupInfos.size() == 0) {
return;
}
V2TIMGroupInfoResult v2TIMGroupInfoResult = v2TIMGroupInfos.get(0);
if (v2TIMGroupInfoResult.getResultCode() == BaseConstants.ERR_SUCC) {
byte[] topicCategoryBytes = v2TIMGroupInfoResult.getGroupInfo().getCustomInfo().get("topic_category");
List<String> topicCategories = null;
if (topicCategoryBytes != null) {
Gson gson = new Gson();
try {
// Parse the group list
topicCategories = gson.fromJson(new String(topicCategoryBytes), List.class);
} catch (JsonParseException e) {
}
}
}
}

@Override
public void onError(int code, String desc) {

}
});
NSArray *groupIDList = @[@"group1"];
[[V2TIMManager sharedInstance] getGroupsInfo:groupIDList
succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {
// Conversation profile obtained successfully
if (groupResultList.count == 0) {
return;
}
V2TIMGroupInfoResult *result = groupResultList.firstObject;
if (result.resultCode != 0) {
return;
}
NSData *categoryData = result.info.customInfo[@"topic_category"];
if (categoryData == nil) {
return;
}
NSArray *categoryList;
NSError *error = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:categoryData
options:NSJSONReadingAllowFragments
error:nil];
if (jsonObject != nil && error == nil) {
// Parse the group list
categoryList = (NSArray *)jsonObject;
}
} fail:^(int code, NSString *desc) {
// Failed to obtain
}];
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_;
};

V2TIMStringVector groupIDList;
groupIDList.PushBack("group1");

auto callback = new ValueCallback<V2TIMGroupInfoResultVector>{};
callback->SetCallback(
[=](const V2TIMGroupInfoResultVector& groupInfoResultList) {
if (groupInfoResultList.Size() == 1) {
const V2TIMGroupInfoResult& groupInfoResult = groupInfoResultList[0];
if (groupInfoResult.resultCode == 0) {
V2TIMGroupInfo info = groupInfoResult.info;
V2TIMCustomInfo customInfo = info.customInfo;
if (customInfo.Count("topic_category")) {
const V2TIMBuffer& topicCategory = customInfo.Get("topic_category");
// Parse the group list
}
}
}

delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to get the community group list
delete callback;
});
V2TIMManager::GetInstance()->GetGroupManager()->GetGroupsInfo(groupIDList, callback);

Adding a topic to a group

You can save the topic group with the customString field of the topic.
Sample code:
Android
iOS and macOS
Windows
Map<String, Object> map = new HashMap<>();
map.put("category", "Group 1");
Gson gson = new Gson();
V2TIMTopicInfo topicInfo = new V2TIMTopicInfo();
topicInfo.setTopicID(topicID);
topicInfo.setCustomString(gson.toJson(map));
V2TIMManager.getGroupManager().setTopicInfo(topicInfo, new V2TIMCallback() {
@Override
public void onSuccess() {
// Topic information modified successfully
}

@Override
public void onError(int code, String desc) {
// Failed to modify the topic information
}
});

NSDictionary *dict = @{@"category": @"Group 1"};
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:dict
options:0
error:&error];
if ([data length] > 0 && error == nil) {
NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
V2TIMTopicInfo *info = [[V2TIMTopicInfo alloc] init];
info.topicID = @"ID of the topic to be set";
info.customString = dataStr;
[[V2TIMManager sharedInstance] setTopicInfo:info succ:^{
// Set the topic profile successfully
} fail:^(int code, NSString *desc) {
// Failed to set the topic profile
}];
}
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_;
};

V2TIMTopicInfo topicInfo;
topicInfo.topicID = "topicID";
topicInfo.customString = u8"{\"category\": \"Group 1\"}}";
topicInfo.modifyFlag = V2TIMGroupInfoModifyFlag::V2TIM_TOPIC_INFO_MODIFY_FLAG_CUSTOM_STRING;

auto callback = new Callback;
callback->SetCallback(
[=]() {
// Topic information modified successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to modify the topic information
delete callback;
});

V2TIMManager::GetInstance()->GetGroupManager()->SetTopicInfo(topicInfo, callback);

Getting the topic group

Use the customString to parse the JSON content after getting the topic list.

Listening for topic callbacks

In V2TIMGroupListener (Android / iOS and macOS / Windows), topic callback methods such as onTopicCreated, onTopicDeleted, and onTopicInfoChanged are added to listen for topic events.
Sample code:
Android
iOS and macOS
Windows
V2TIMGroupListener v2TIMGroupListener = new V2TIMGroupListener() {
@Override
public void onTopicCreated(String groupID, String topicID) {
// Listen for topic creation notifications
}

@Override
public void onTopicDeleted(String groupID, List<String> topicIDList) {
// Listen for topic deletion notifications
}

@Override
public void onTopicInfoChanged(String groupID, V2TIMTopicInfo topicInfo) {
// Listen for topic information update notifications
}
};
V2TIMManager.getInstance().addGroupListener(v2TIMGroupListener);
[[V2TIMManager sharedInstance] addGroupListener:self];
- (void)onTopicCreated:(NSString *)groupID topicID:(NSString *)topicID {
// Listen for topic creation notifications
}
- (void)onTopicDeleted:(NSString *)groupID topicIDList:(NSArray<NSString *> *)topicIDList {
// Listen for topic deletion notifications
}
- (void)onTopicChanged:(NSString *)groupID topicInfo:(V2TIMTopicInfo *)topicInfo {
// Listen for topic information update notifications
}
class GroupListener final : public V2TIMGroupListener {
public:
GroupListener() = default;
~GroupListener() override = default;

void OnTopicCreated(const V2TIMString& groupID, const V2TIMString& topicID) override {
// Listen for topic creation notifications
}
void OnTopicDeleted(const V2TIMString& groupID, const V2TIMStringVector& topicIDList) override {
// Listen for topic deletion notifications
}
void OnTopicChanged(const V2TIMString& groupID, const V2TIMTopicInfo& topicInfo) override {
// Listen for topic information update notifications
}
};

// 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);

Topic Messages

Topic messages can be used in the same way as ordinary messages and involve the following APIs:
Feature
API
Description
sendMessage (Android / iOS & Mac / Windows)
Set groupID to the topic ID.
onRecvNewMessage method in V2TIMAdvancedMsgListener (Android / iOS & Mac / Windows)
Set groupID in the message to the topic ID.
markGroupMessageAsRead (Android / iOS & Mac / Windows)
Set groupID to the topic ID.
getGroupHistoryMessageList (Android / iOS & Mac / Windows)
Set groupID to the topic ID.
revokeMessage (Android / iOS & Mac / Windows)
Set groupID to the topic ID.