TencentImSDKPlugin.v2TIMManager.getGroupManager()
core class.TencentImSDKPlugin.v2TIMManager.getMessageManager()
core class.V2TIMGroupInfo
object (Details) and set groupType
to Community
and isSupportTopic
to true
/YES
.createGroup
(Details) API to create the community group.// Create a topic-enabled communitygroupManager.createGroup(groupType: "Community", groupName: "Community",isSupportTopic: true);
// Getting the list of community groups joinedV2TimValueCallback<List<V2TimGroupInfo>> groupList = await groupManager.getJoinedCommunityList();
Category | Feature | API |
Community group management | ||
| ||
| ||
| ||
| ||
Community group member management | ||
| ||
| ||
|
V2TIMTopicInfo
(Details) object.createTopicInCommunity
(Details) API to create a topic.// Create a topicgroupManager.createTopicInCommunity(groupID: "groupID", topicInfo: V2TimTopicInfo.fromJson({"topicName":"topic"}));
// Delete a topicgroupManager.deleteTopicFromCommunity(groupID: "",topicIDList:["topicID"]);
V2TIMTopicInfo
(Details) object and modify fields as needed.setTopicInfo
(Details) API to modify topic information.// Modify topic informationgroupManager.setTopicInfo(topicInfo:V2TimTopicInfo.fromJson({"topicName":"topicName"}));
topicIDList
is an empty array, the list of all topics of the community group will be got.topicIDList
is the ID of specified topics, the list of the specified topics will be got.// Get the topic listgroupManager.getTopicInfoList(groupID: "",topicIDList: ['topicID']);
customInfo
of a community saves the topic group list of the community, while the customString
field of each topic stores the topic group.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 List<String>
format.customString
of V2TimTopicInfo
.key
value of the customInfo
field for the topic group list of the community (group).
The following sample code names it topic_category
.getCommunityCategoryList(String groupID)
method. Sample code:getCommunityCategoryList(String groupID) async {final Map<String, String>? customInfo = await getCommunityCustomInfo(groupID);if(customInfo != null){final String? categoryListString = customInfo["topic_category"];if(categoryListString != null && categoryListString.isNotEmpty){return jsonDecode(categoryListString);}}}Future<Map<String, String>?> getCommunityCustomInfo(String groupID) async {V2TimValueCallback<List<V2TimGroupInfoResult>> res =await TencentImSDKPlugin.v2TIMManager.getGroupManager().getGroupsInfo(groupIDList: [groupID]);if(res.code != 0){final V2TimGroupInfoResult? groupInfo = res.data?[0];if(groupInfo != null){Map<String, String>? customInfo = groupInfo.groupInfo?.customInfo;return customInfo;}}return null;}
customInfo
in groupInfo
. Here is a Map
, and the key
value is the name of the field for the topic group list you defined.getCommunityCustomInfo
method is implemented in the above section. Sample code:setCommunityCategoryList(String groupID, String groupType, List<String> newCategoryList) async {final Map<String, String>? customInfo = await getCommunityCustomInfo(groupID);customInfo?["topic_category"] = jsonEncode(newCategoryList);TencentImSDKPlugin.v2TIMManager.getGroupManager().setGroupInfo(info: V2TimGroupInfo(customInfo: customInfo,groupID: groupID,groupType: groupType,// ...Other profiles));}
V2TimTopicInfo customString
.
For example, the recommended format for categoryName
in the code below is {"category":"Group 1"}
.addCategoryForTopic(String groupID, String categoryName) {TencentImSDKPlugin.v2TIMManager.getGroupManager().setTopicInfo(topicInfo: V2TimTopicInfo(customString: categoryName),groupID: groupID, // Group ID of the topic);}
V2TIMGroupListener
(Details), topic related callback methods onTopicCreated
, onTopicDeleted
, and onTopicInfoChanged
are added for topic event listening. V2TIMGroupListener v2TIMGroupListener = new V2TIMGroupListener() {onTopicCreated(String groupID, String topicID) {// Listen for topic creation notifications}onTopicDeleted(String groupID, List<String> topicIDList) {// Listen for topic deletion notifications}onTopicInfoChanged(String groupID, V2TIMTopicInfo topicInfo) {// Listen for topic information update notifications}};V2TIMManager.getInstance().addGroupListener(v2TIMGroupListener);
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 | Set `groupID` to the topic ID. | |
Gets historical messages | Set `groupID` to the topic ID. | |
Recalls a message | Set `groupID` to the topic ID. |
Was this page helpful?