功能描述
群成员资料类为
V2TIMGroupMemberFullInfo
,内含群成员 userID、自定义信息、角色、禁言等信息。
相关方法在核心类 V2TIMGroupManager(Android)
/ V2TIMManager(Group)(iOS & Mac)
中。获取群成员资料
示例代码如下:
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
设置自己的群名片(nameCard
)、自定义字段(customInfo
)等信息。说明
直播群(AVChatRoom)不存储群成员信息,设置直播群成员名片不适用于直播群。
注意
群成员自定义字段最多可设置 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) {// 修改失败}});