멤버 정보
Feature Description
The class for the group member profile is
V2TIMGroupMemberFullInfo
, which contains the userID
, custom information, role, and muting information of the group member.Getting the Profile of Group Members
You can call
getGroupMembersInfo
(Android / iOS and macOS / Windows) to get the group member profile. This API supports passing in multiple userID
values at a time to get group member profiles in batch and therefore improve the network transfer efficiency.Sample code:
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) {// Obtained successfully}@Overridepublic void onError(int code, String desc) {// Failed to obtain}});
[[V2TIMManager sharedInstance] getGroupMembersInfo:@"groupA" memberList:@[@"user1"] succ:^(NSArray<V2TIMGroupMemberFullInfo *> *memberList) {// Obtained successfully} 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_;};V2TIMString groupID = "groupA";V2TIMStringVector memberList;memberList.PushBack("userA");memberList.PushBack("userB");auto callback = new ValueCallback<V2TIMGroupInfoVector>{};callback->SetCallback([=](const V2TIMGroupMemberFullInfoVector& groupMemberFullInfoList) {// Obtained successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to obtaindelete callback;});V2TIMManager::GetInstance()->GetGroupManager()->GetGroupMembersInfo(groupID, memberList, callback);
Modifying Group Member Profiles
The group owner or admin can call the
setGroupMemberInfo
API (Android / iOS and macOS / Windows) to modify the group name card (nameCard
), custom field (customInfo
), and other information of a group member.Ordinary group members can call
setGroupMemberInfo
to set their group name card (nameCard
) and custom field (customInfo
).To modify a custom group member field, you must configure it in advance in the Console. Configuration path: Applications > Your App > Chat > Configuration > Group Configuration > Custom Group Member Field.
Note
1. Audio-video group (AVChatRoom) doesn't store group member information, the name card of a group member cannot be set.
2. You can set up to five custom group member fields, which cannot be deleted and whose name and type cannot be changed.
Sample code:
V2TIMGroupMemberFullInfo memberFullInfo = new V2TIMGroupMemberFullInfo();// Specify a group membermemberFullInfo.setUserID("userA");// Set the `nameCard` value to be modifiedmemberFullInfo.setNameCard("userA_namecard");// Set a group member custom fieldMap<String, byte[]> customMap = new HashMap<>();customMap.put("member_key1", "value1".getBytes());memberFullInfo.setCustomInfo(customMap);V2TIMManager.getGroupManager().setGroupMemberInfo("groupA", memberFullInfo, new V2TIMCallback() {@Overridepublic void onSuccess() {// Modified successfully}@Overridepublic void onError(int code, String desc) {// Failed to modify}});
V2TIMGroupMemberFullInfo *memberFullInfo = [[V2TIMGroupMemberFullInfo alloc] init];// Specify a group membermemberFullInfo.userID = @"user1";// Set the `nameCard` value to be modifiedmemberFullInfo.nameCard = @"user1_namecard";// Set a group member custom fieldmemberFullInfo.customInfo = @{@"member_key1" : [@"value1" dataUsingEncoding:NSUTF8StringEncoding]};[[V2TIMManager sharedInstance] setGroupMemberInfo:@"groupA" info:memberFullInfo succ:^{// Modified successfully} fail:^(int code, NSString *desc) {// Failed to modify}];
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_;};// Specify a group memberV2TIMGroupMemberFullInfo info;info.userID = "userA";// Set the `nameCard` value to be modifiedinfo.nameCard = "userA_namecard";info.modifyFlag = V2TIMGroupMemberInfoModifyFlag::V2TIM_GROUP_MEMBER_INFO_MODIFY_FLAG_NAME_CARD;// Set a group member custom fieldV2TIMCustomInfo 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([=]() {// Modified successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to modifydelete callback;});V2TIMManager::GetInstance()->GetGroupManager()->SetGroupMemberInfo("userA", info, callback);