searchGroupMembers
(Android / iOS & Mac / Windows) 搜索本地群成员。
您可以设置搜索关键字 keywordList
,并指定搜索的范围,即是否搜索群成员的 memberUserID
、memberNickName
、memberRemark
、memberNameCard
字段。searchGroupMembers
入参 V2TIMGroupMemberSearchParam
(Android / iOS & Mac / Windows) 中的 groupIDList
是否为空(null
/nil
),分为两种情况:groupIDList
为空,代表搜索全部群中的群成员,返回的结果会按照 groupID
进行分类;groupIDList
不为空,代表搜索指定群中的群成员。V2TIMGroupMemberSearchParam searchParam = new V2TIMGroupMemberSearchParam();searchParam.setGroupIDList(groupIDList);searchParam.setKeywordList(keywordList);searchParam.setSearchMemberUserID(true);searchParam.setSearchMemberNickName(true);searchParam.setSearchMemberRemark(true);searchParam.setSearchMemberNameCard(true);V2TIMManager.getGroupManager().searchGroupMembers(searchParam, new V2TIMValueCallback<HashMap<String, List<V2TIMGroupMemberFullInfo>>>() {@Overridepublic void onSuccess(HashMap<String, List<V2TIMGroupMemberFullInfo>> stringListHashMap) {StringBuilder stringBuilder = new StringBuilder();for (Map.Entry<String, List<V2TIMGroupMemberFullInfo>> entry : stringListHashMap.entrySet()) {// 群 IDString groupID = entry.getKey();// 群成员列表List<V2TIMGroupMemberFullInfo> memberFullInfoList = entry.getValue();}}}@Overridepublic void onError(int code, String desc) {// 搜索群成员失败}});
V2TIMGroupMemberSearchParam *searchParam = [[V2TIMGroupMemberSearchParam alloc] init];searchParam.groupIDList = @[@"group1", @"group2"];searchParam.keywordList = @[@"keyword1", @"keyword2"];searchParam.isSearchMemberUserID = YES;searchParam.isSearchMemberNickName = YES;searchParam.isSearchMemberRemark = YES;searchParam.isSearchMemberNameCard = YES;[[V2TIMManager sharedInstance] searchGroupMembers:searchParam succ:^(NSDictionary<NSString *,NSArray<V2TIMGroupMemberFullInfo *> *> *memberList) {for (NSString *key in memberList.allKeys) {// 群 IDNSString *groupID = key;// 群成员列表NSArray *memberFullInfoList = memberList[key];}} 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_;};V2TIMGroupMemberSearchParam param;param.groupIDList = groupIDList;param.keywordList = keywordList;param.isSearchMemberUserID = true;param.isSearchMemberNickName = true;param.isSearchMemberRemark = true;param.isSearchMemberNameCard = true;auto callback = new ValueCallback<V2TIMGroupSearchGroupMembersMap>{};callback->SetCallback([=](const V2TIMGroupSearchGroupMembersMap& groupSearchGroupMembersMap) {V2TIMStringVector allKeys = groupSearchGroupMembersMap.AllKeys();for (size_t i = 0; i < allKeys.Size(); i++) {// 群 IDconst V2TIMString& groupID = allKeys[i];// 群成员列表V2TIMGroupMemberFullInfoVector groupMemberFullInfoList = groupSearchGroupMembersMap.Get(groupID);}delete callback;},[=](int error_code, const V2TIMString& error_message) {// 搜索群成员失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->SearchGroupMembers(param, callback);
本页内容是否解决了您的问题?