Community Management
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.
Community groups are used to manage group members. All topics under the same community group are shared among members, who can send and receive messages within each topic independently.
Community and topic management APIs are in the
TencentImSDKPlugin.v2TIMManager.getGroupManager()
core class.The topic message APIs are in the
TencentImSDKPlugin.v2TIMManager.getMessageManager()
core class.Note:
To use the feature, you need to purchase the Ultimate 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 (Details) and set groupType
to Community
and isSupportTopic
to true
/YES
.2. Call the
createGroup
API (Details) to create a community.Sample code:
// Create a topic-enabled communitygroupManager.createGroup(groupType: "Community", groupName: "Community",isSupportTopic: true);
Getting the list of community groups joined
Sample code:
// Getting the list of community groups joinedconst groupList = await groupManager.getJoinedCommunityList();
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 | ||
| ||
| ||
| ||
| ||
Community group member management | ||
| ||
| ||
|
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
(Details) object.2. Call the
createTopicInCommunity
API (Details) to create a topic.Sample code:
// Create a topicgroupManager.createTopicInCommunity("groupID", {topicName: "topic",});
Deleting a topic
Sample code:
// Delete a topicgroupManager.deleteTopicFromCommunity("groupID", ["topicID"]);
Modifying topic information
You need to perform two steps to modify the information of a topic:
1. Create the
V2TIMTopicInfo
object (Details) and set the fields to be modified.2. Call the
setTopicInfo
API (Details) to modify the information of a topic.Sample code:
// Modify topic informationgroupManager.setTopicInfo({topicName: "topicName",});
Getting the topic list
Getting 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:
// Get the topic listgroupManager.getTopicInfoList("groupID", ["topicID"]);
Topic groups
The community is a new powerful tool for entertainment collaboration and supports the community-group-topic hierarchy to isolate messages.
The
customInfo
of a community saves the topic group list of the community, while the customString
field of each topic stores the topic group.When a community is loaded, the
customInfo
field for the topic group list of the community (group) is used to display the group list. We recommend you store the field in the string[]
format.To get the topics in each group, traverse the topic list and get the group of each topic through the
customString
of V2TimTopicInfo
.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 categoryList
.Getting the list of groups in the community
Call the
getCommunityCategoryList(String groupID)
method. Sample code:const getCommunityCategoryList = async (groupID) => {const customInfo = await getCommunityCustomInfo(groupID);if (customInfo != null) {const categoryListString = customInfo["categoryList"];if (categoryListString != null && categoryListString !== "") {return JSON.parse(categoryListString);}}};const getCommunityCustomInfo = async (groupID) => {const groupIDList = [groupID];const res = await TencentImSDKPlugin.v2TIMManager.getGroupManager().getGroupsInfo(groupIDList);if (res.code != 0) {const groupInfo = res.data[0];if (groupInfo != null) {const customInfo = groupInfo.groupInfo?.customInfo;return customInfo;}}return null;};
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.The
getCommunityCustomInfo
method is implemented in the above section. Sample code:const setCommunityCategoryList = async (groupID,groupType,newCategoryList) => {const customInfo = await getCommunityCustomInfo(groupID);customInfo["categoryList"] = JSON.parse(newCategoryList);TencentImSDKPlugin.v2TIMManager.getGroupManager().setGroupInfo({customInfo: customInfo,groupID: groupID,groupType: groupType,// ...Other profiles});};
Adding a topic to a group
Sample code:
const addCategoryForTopic = (groupID, categoryName) => {TencentImSDKPlugin.v2TIMManager.getGroupManager().setTopicInfo({customString: categoryName,});};
Getting the topic group
Listening for topic callbacks
In
V2TIMGroupListener
(Details), topic callback methods such as onTopicCreated
, onTopicDeleted
, and onTopicInfoChanged
are added to listen for topic events.Sample code:
const v2TIMGroupListener = {onTopicCreated: (groupID, topicID) => {// Listen for topic creation notifications},onTopicDeleted: (groupID, topicIDList) => {// Listen for topic deletion notifications},onTopicInfoChanged: (groupID, topicInfo) => {// Listen for topic information update notifications},};V2TIMManager.getInstance().addGroupListener(v2TIMGroupListener);
Topic Messages
Topic messages can be used in the same way as ordinary messages and involve the following APIs:
Feature | API | Description |
Sends a message | Set `groupID` to the topic ID. | |
Receives a message | Set `groupID` in the message to the topic ID. | |
Marks a message as read | markGroupMessageAsRead (TS | Set `groupID` to the topic ID. |
Gets historical messages | getGroupHistoryMessageList (TS | Set `groupID` to the topic ID. |
Recalls a message | Set `groupID` to the topic ID. |