群成员资料
功能描述
群成员资料类为
V2TIMGroupMemberFullInfo
,内含群成员 userID、自定义信息、角色、禁言等信息。获取群成员资料
您可以调用
getGroupMembersInfo
(Android / iOS & Mac / Windows) 获取群成员资料。该接口支持批量获取,您可以一次传入多个 userID
获取多个群成员的资料,从而提升网络传输效率。示例代码如下:
List<String> userIDList = new ArrayList<>();userIDList.add("userA");userIDList.add("userB");V2TIMManager.getGroupManager().getGroupMembersInfo("groupA", userIDList, new V2TIMValueCallback<List<V2TIMGroupMemberFullInfo>>() {@Overridepublic void onSuccess(List<V2TIMGroupMemberFullInfo> v2TIMGroupMemberFullInfos) {// 获取成功}@Overridepublic void onError(int code, String desc) {// 获取失败}});
[[V2TIMManager sharedInstance] getGroupMembersInfo:@"groupA" memberList:@[@"user1"] succ:^(NSArray<V2TIMGroupMemberFullInfo *> *memberList) {// 获取成功} 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_;};V2TIMString groupID = "groupA";V2TIMStringVector memberList;memberList.PushBack("userA");memberList.PushBack("userB");auto callback = new ValueCallback<V2TIMGroupMemberFullInfoVector>{};callback->SetCallback([=](const V2TIMGroupMemberFullInfoVector& groupMemberFullInfoList) {// 获取成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->GetGroupMembersInfo(groupID, memberList, callback);
修改群成员资料
群主或管理员可以调用
setGroupMemberInfo
(Android / iOS & Mac / Windows) 接口修改群成员的群名片(nameCard
)、自定义字段(customInfo
)等与群成员相关的资料。普通群成员可以调用
setGroupMemberInfo
设置自己的群名片(nameCard
)、自定义字段(customInfo
)等信息。如果要修改群成员自定义字段,您必须提前在 控制台 配置好该字段,配置路径:Applications > Your App > Chat > Configuration > Group Configuration > Custom Group Member Field。
注意
1. 直播群(AVChatRoom)不存储群成员信息,设置直播群成员名片不适用于直播群。
2. 群成员自定义字段最多可设置 5 个。字段创建后,该字段将不可删除,也无法修改字段名与字段类型。
示例代码如下:
V2TIMGroupMemberFullInfo memberFullInfo = new V2TIMGroupMemberFullInfo();// 指定修改的群成员memberFullInfo.setUserID("userA");// 设置修改的 nameCard 值memberFullInfo.setNameCard("userA_namecard");// 设置群成员自定义字段Map<String, byte[]> customMap = new HashMap<>();customMap.put("member_key1", "value1".getBytes());memberFullInfo.setCustomInfo(customMap);V2TIMManager.getGroupManager().setGroupMemberInfo("groupA", memberFullInfo, new V2TIMCallback() {@Overridepublic void onSuccess() {// 修改成功}@Overridepublic void onError(int code, String desc) {// 修改失败}});
V2TIMGroupMemberFullInfo *memberFullInfo = [[V2TIMGroupMemberFullInfo alloc] init];// 指定修改的群成员memberFullInfo.userID = @"user1";// 设置修改的 nameCard 值memberFullInfo.nameCard = @"user1_namecard";// 设置群成员自定义字段memberFullInfo.customInfo = @{@"member_key1" : [@"value1" dataUsingEncoding:NSUTF8StringEncoding]};[[V2TIMManager sharedInstance] setGroupMemberInfo:@"groupA" info:memberFullInfo 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_;};// 指定修改的群成员V2TIMGroupMemberFullInfo info;info.userID = "userA";// 设置修改的 nameCard 值info.nameCard = "userA_namecard";info.modifyFlag = V2TIMGroupMemberInfoModifyFlag::V2TIM_GROUP_MEMBER_INFO_MODIFY_FLAG_NAME_CARD;// 设置群成员自定义字段V2TIMCustomInfo customInfo;std::string str{u8"value1"};customInfo.Insert("member_key1", {reinterpret_cast<const uint8_t*>(str.data()), str.size()});info.customInfo = customInfo;info.modifyFlag |= V2TIMGroupMemberInfoModifyFlag::V2TIM_GROUP_MEMBER_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()->SetGroupMemberInfo("userA", info, callback);