V2TIMGroupManager(Android)
/ V2TIMManager(Group)(iOS & Mac)
中。V2TIMMessageManager(Android)
/ V2TIMManager(Message)(iOS & Mac)
中。V2TIMGroupInfo
(Android / iOS & Mac / Windows) 对象,其中 groupType
设置为 Community
,isSupportTopic
设置为 true
/YES
。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>() {@Overridepublic void onSuccess(String groupID) {// 创建社群成功}@Overridepublic void onError(int code, String desc) {// 创建社群失败}});
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) {// 创建社群成功} fail:^(int code, NSString *desc) {// 创建社群失败}];
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) {// 创建社群成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 创建社群失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->CreateGroup(info, {}, callback);
V2TIMManager.getGroupManager().getJoinedCommunityList(new V2TIMValueCallback<List<V2TIMGroupInfo>>() {@Overridepublic void onSuccess(List<V2TIMGroupInfo> v2TIMGroupInfos) {// 获取社群列表成功}@Overridepublic void onError(int code, String desc) {// 获取社群列表失败}});
[[V2TIMManager sharedInstance] getJoinedCommunityList:^(NSArray<V2TIMGroupInfo *> *groupList) {// 获取社群列表成功} fail:^(int code, NSString *desc) {// 获取社群列表失败}];
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) {// 获取社群列表成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取社群列表失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->GetJoinedCommunityList(callback);
分类 | 功能 | 接口 |
社群管理 | ||
| ||
| ||
| ||
| ||
社群成员管理 | ||
| ||
| ||
|
V2TIMTopicInfo topicInfo = new V2TIMTopicInfo();topicInfo.setTopicName(topicName);topicInfo.setTopicFaceUrl(topicFaceUrl);topicInfo.setIntroduction(topicIntroduction);topicInfo.setNotification(topicNotification);topicInfo.setCustomString(topicCustomString);// groupID 填支持话题的社群 IDV2TIMManager.getGroupManager().createTopicInCommunity(groupID, topicInfo, new V2TIMValueCallback<String>() {@Overridepublic void onSuccess(String topicID) {// 创建话题成功}@Overridepublic void onError(int code, String desc) {// 创建话题失败}});
V2TIMTopicInfo *topicInfo = [[V2TIMTopicInfo alloc] init];topicInfo.topicName = @"topicName";topicInfo.topicFaceURL = @"topicFaceUrl";topicInfo.introduction = @"topicIntroduction";topicInfo.notification = @"topicNotification";topicInfo.customString = @"topicCustomString";// groupID 填支持话题的社群 ID[[V2TIMManager sharedInstance] createTopicInCommunity:@"groupID" topicInfo:topicInfo succ:^(NSString *topicID) {// 创建话题成功} fail:^(int code, NSString *desc) {// 创建话题失败}];
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) {// 创建话题成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 创建话题失败delete callback;});// groupID 填支持话题的社群 IDV2TIMManager::GetInstance()->GetGroupManager()->CreateTopicInCommunity("groupID", topicInfo, callback);
V2TIMManager.getGroupManager().deleteTopicFromCommunity(groupID, topicIDList, new V2TIMValueCallback<List<V2TIMTopicOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMTopicOperationResult> v2TIMTopicOperationResults) {// 删除话题成功}@Overridepublic void onError(int code, String desc) {// 删除话题失败}});
[[V2TIMManager sharedInstance] deleteTopicFromCommunity:@"groupID" topicIDList:@[@"topic1", @"topic2"] succ:^(NSMutableArray<V2TIMTopicOperationResult *> *resultList) {// 删除话题成功} fail:^(int code, NSString *desc) {// 删除话题失败}];
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) {// 删除话题成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 删除话题失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->DeleteTopicFromCommunity("groupID", topicIDList, callback);
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() {@Overridepublic void onSuccess() {// 修改话题信息成功}@Overridepublic void onError(int code, String desc) {// 修改话题信息失败}});
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:^{// 修改话题信息成功} fail:^(int code, NSString *desc) {// 修改话题信息失败}];
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([=]() {// 修改话题信息成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 修改话题信息失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->SetTopicInfo(topicInfo, callback);
setInheritMessageReceiveOptionFromCommunity
(Android / iOS & Mac / Windows)。V2TIMTopicInfo topicInfo = new V2TIMTopicInfo();topicInfo.setTopicID(topicID);topicInfo.setInheritMessageReceiveOptionFromCommunity(true, new V2TIMCallback() { @Override public void onSuccess() { // 继承成功 } @Override public void onError(int code, String desc) { // 继承失败 } });
V2TIMTopicInfo *topicInfo = [[V2TIMTopicInfo alloc] init];topicInfo.topicID = @"topicID";[topicInfo setInheritMessageReceiveOptionFromCommunity:YES succ:^{// 继承成功} fail:^(int code, NSString *desc) {// 继承失败}];
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([=]() {// 继承成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 继承失败delete callback;});V2TIMTopicInfo topicInfo;topicInfo.topicID = "topicID";topicInfo.SetInheritMessageReceiveOptionFromCommunity(true, callback);
V2TIMManager.getGroupManager().getTopicInfoList(groupID, topicIDList, new V2TIMValueCallback<List<V2TIMTopicInfoResult>>() {@Overridepublic void onSuccess(List<V2TIMTopicInfoResult> v2TIMTopicInfoResults) {// 获取话题列表成功}@Overridepublic void onError(int code, String desc) {// 获取话题列表失败}});
[[V2TIMManager sharedInstance] getTopicInfoList:@"groupID" topicIDList:@[@"topic1", @"topic2"] succ:^(NSMutableArray<V2TIMTopicInfoResult *> *resultList) {// 获取话题列表成功} fail:^(int code, NSString *desc) {// 获取话题列表失败}];
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) {// 获取话题列表成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取话题列表失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->GetTopicInfoList("groupID", topicIDList, callback);
customInfo
(Android / iOS & Mac / Windows) 中定义一个字段保存该社群的话题分组列表;每个话题所属的分组,存储于话题资料的 customString
(Android / iOS & Mac / Windows) 字段中。customInfo
的话题分组列表字段,展示分组列表。customString
获取分组名分配到所属分组中。customInfo
的话题分组列表字段名,key 值,可由您自行定义。以下示例代码中,将其命名为 topic_category
。groupInfo
的 customInfo
即可。此处为一个 Map,key 值是您定义的话题分组列表字段名。
示例代码如下:List<String> categoryList = new ArrayList<>();categoryList.add("分组1");categoryList.add("分组2");byte[] categoriesByteArray = gson.toJson(categoryList).getBytes();Map<String, byte[]> customMap = new HashMap<>();// 需要先在控制台配置群自定义字段 topic_categorycustomMap.put("topic_category", categoriesByteArray);V2TIMGroupInfo modifyInfo = new V2TIMGroupInfo();modifyInfo.setGroupID(groupID);modifyInfo.setCustomInfo(customMap);V2TIMManager.getGroupManager().setGroupInfo(modifyInfo, new V2TIMCallback() {@Overridepublic void onSuccess() {// 修改群资料成功}@Overridepublic void onError(int code, String desc) {// 修改群资料失败}});
NSArray *categoryList = @[@"分组 1", @"分组 2"];NSError *error = nil;NSData *data = [NSJSONSerialization dataWithJSONObject:categoryListoptions:NSJSONWritingPrettyPrintederror:&error];if ([data length] > 0 && error == nil) {// 需要先在控制台配置群自定义字段 topic_categoryNSDictionary *customInfo = @{@"topic_category": data};V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];info.groupID = @"需要修改的群 ID";info.customInfo = customInfo;[[V2TIMManager sharedInstance] setGroupInfo:infosucc:^{// 修改群资料成功} fail:^(int code, NSString *desc) {// 修改群资料失败}];}
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"[\\"分组1\\", \\"分组2\\"]"};// 需要先在控制台配置群自定义字段 topic_categorycustomInfo.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([=]() {// 修改群资料成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 修改群资料失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->SetGroupInfo(info, callback);
String groupID = "group1";List<String> groupIDList = new ArrayList<>();groupIDList.add(groupID);V2TIMManager.getGroupManager().getGroupsInfo(groupIDList, new V2TIMValueCallback<List<V2TIMGroupInfoResult>>() {@Overridepublic 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 {// 解析出分组列表topicCategories = gson.fromJson(new String(topicCategoryBytes), List.class);} catch (JsonParseException e) {}}}}@Overridepublic void onError(int code, String desc) {}});
NSArray *groupIDList = @[@"group1"];[[V2TIMManager sharedInstance] getGroupsInfo:groupIDListsucc:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {// 获取成功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:categoryDataoptions:NSJSONReadingAllowFragmentserror:nil];if (jsonObject != nil && error == nil) {// 解析出分组列表categoryList = (NSArray *)jsonObject;}} fail:^(int code, NSString *desc) {// 获取失败}];
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");// 解析出分组列表 ...}}}delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取社群的分组列表失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->GetGroupsInfo(groupIDList, callback);
customString
字段来保存。Map<String, Object> map = new HashMap<>();map.put("category", "分组1");Gson gson = new Gson();V2TIMTopicInfo topicInfo = new V2TIMTopicInfo();topicInfo.setTopicID(topicID);topicInfo.setCustomString(gson.toJson(map));V2TIMManager.getGroupManager().setTopicInfo(topicInfo, new V2TIMCallback() {@Overridepublic void onSuccess() {// 修改话题信息成功}@Overridepublic void onError(int code, String desc) {// 修改话题信息失败}});
NSDictionary *dict = @{@"category": @"分组 1"};NSError *error = nil;NSData *data = [NSJSONSerialization dataWithJSONObject:dictoptions:0error:&error];if ([data length] > 0 && error == nil) {NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];V2TIMTopicInfo *info = [[V2TIMTopicInfo alloc] init];info.topicID = @"需要设置的话题 ID";info.customString = dataStr;[[V2TIMManager sharedInstance] setTopicInfo:info succ:^{// 设置话题资料成功} fail:^(int code, NSString *desc) {// 设置话题资料失败}];}
class Callback