그룹 멤버 검색
Overview
Only locally stored group members can be searched for, such as the list of group members or group member profiles that have been pulled.
Note:
The local group member search feature is supported only by the Enhanced SDK on v5.4.666 or later. It cannot be used for audio-video groups (AVChatRoom) as the group members are not stored locally.
The local group member search feature is only available on the IM Premium edition. To use it, purchase the Premium Edition.
Searching for Local Group Members
Call the
searchGroupMembers
API (Android / iOS and Mac / Windows) to search for local group members.
You can set the search keyword keywordList
and specify the search scope to set whether to search by the memberUserID
, memberNickName
, memberRemark
, and memberNameCard
fields of group members.Depending on whether
groupIDList
of V2TIMGroupMemberSearchParam
(Android / iOS and macOS / Windows) in searchGroupMembers
is empty (null
/nil
), there are two cases:If
groupIDList
is left empty, members in all the groups will be searched for and returned by groupID
.If
groupIDList
is not left empty, members in the specified group will be searched for.Sample code:
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()) {// Group IDString groupID = entry.getKey();// Group member listList<V2TIMGroupMemberFullInfo> memberFullInfoList = entry.getValue();}}}@Overridepublic void onError(int code, String desc) {// Failed to find the group members}});
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) {// Group IDNSString *groupID = key;// Group member listNSArray *memberFullInfoList = memberList[key];}} fail:^(int code, NSString *desc) {// Failed to find the group members}];
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++) {// Group IDconst V2TIMString& groupID = allKeys[i];// Group member listV2TIMGroupMemberFullInfoVector groupMemberFullInfoList = groupSearchGroupMembersMap.Get(groupID);}delete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to find the group membersdelete callback;});V2TIMManager::GetInstance()->GetGroupManager()->SearchGroupMembers(param, callback);