GroupSearchGroupMembers

功能介绍

搜索群成员

群成员搜索只能搜索本地存储过的群成员,比如拉取过的群成员列表、拉取过的群成员资料等。

SDK 会在本地搜索指定群 ID 列表中,群成员信息(名片、好友备注、昵称、userID)包含于关键字列表 keywordList 的所有群成员并返回群 ID 和群成员列表的 map,关键字列表最多支持5个。

如搜索不到请先调用GroupGetMemberInfoList将成员信息存储到本地数据库再调用此接口进行搜索,关键字列表最多支持5个。

直播群(AVChatRoom)不在本地存储群成员,无法使用群成员搜索功能。

如果设置 group_search_member_params_groupid_list 为空,代表搜索全部群中的群成员,返回的结果会按照 groupID 进行分类;

如果设置 group_search_member_params_groupid_list 不为空,代表搜索指定群中的群成员。

参数详解

重载1

参数名称 参数类型 是否必填 描述
json_group_search_group_members_param GroupMemberSearchParam 搜索群成员参数
callback ValueCallback< List< GroupGetOnlineMemberCountResult > > 异步回调 返回值的json_param的格式为json

重载2

参数名称 参数类型 是否必填 描述
json_group_search_group_members_param GroupMemberSearchParam 搜索群成员参数
callback ValueCallback< string > 异步回调 返回值的json_param的格式为string

返回模板

TIMResult

调用成功后回调函数参数:
code:int
desc:string
json_param:
'[{
  "group_search_member_result_groupid": "lamarzhang_group_public",
  "group_search_member_result_menber_info_list": [{
      "group_member_info_custom_info": [{
          "group_info_custom_string_info_key": "group_member_p",
          "group_info_custom_string_info_value": ""
      }, {
          "group_info_custom_string_info_key": "group_member_p2",
          "group_info_custom_string_info_value": ""
      }],
      "group_member_info_identifier": "98826",
      "group_member_info_join_time": 1620810613,
      "group_member_info_member_role": 4,
      "group_member_info_msg_flag": 0,
      "group_member_info_msg_seq": 0,
      "group_member_info_name_card": "",
      "group_member_info_shutup_time": 0
  }]
}]' // Json Key请参考[GroupGetOnlineMemberCountResult]
user_data:string

返回值详解

名称 数值类型 描述
TIMResult TIMResult 调用接口的返回值
code int 值为ERR_SUCC表示成功,其他值表示失败。详情请参考 错误码
desc string 错误描述字符串
json_param string Json字符串,不同的接口,Json字符串不一样 Json Key请参考GroupGetOnlineMemberCountResult
user_data string ImSDK负责透传的用户自定义数据,未做任何处理

代码示例

using UnityEngine;
using UnityEngine.UI;
using com.tencent.im.unity.demo.types;
using UnityEngine.SceneManagement;
using com.tencent.imsdk.unity;
using com.tencent.imsdk.unity.types;
using com.tencent.imsdk.unity.enums;
using System;
using com.tencent.im.unity.demo.utils;
using System.Collections;
using System.Collections.Generic;
using EasyUI.Toast;
public class GroupSearchGroupMembers : MonoBehaviour
{
  public List<FriendGroupInfo> GroupList = new List<FriendGroupInfo>();
  public HashSet<string> SelectedGroups = new HashSet<string>();
  public HashSet<string> OriSelectedFriends = new HashSet<string>();
  public InputField Input;
  public Toggle IsSearchUserId;
  public Toggle IsSearchNickName;
  public Toggle IsSearchRemark;
  public Toggle IsSearchNameCard;
  public Text Header;
  public Text Result;
  public Button Submit;
  public Button Copy;
  string[] Labels = new string[] { "SelectGroupLabel", "KeywordLabel", "GroupSearchKeywordPlaceHolder", "IsSearchUserIdLabel", "IsSearchNickNameLabel", "IsSearchRemarkLabel", "IsSearchNameCardLabel" };
  void Start()
  {
    foreach (string label in Labels)
    {
      GameObject.Find(label).GetComponent<Text>().text = Utils.t(label);
    }
    Header = GameObject.Find("HeaderText").GetComponent<Text>();
    Input = GameObject.Find("InputField").GetComponent<InputField>();
    IsSearchUserId = GameObject.Find("IsSearchUserId").GetComponent<Toggle>();
    IsSearchNickName = GameObject.Find("IsSearchNickName").GetComponent<Toggle>();
    IsSearchRemark = GameObject.Find("IsSearchRemark").GetComponent<Toggle>();
    IsSearchNameCard = GameObject.Find("IsSearchNameCard").GetComponent<Toggle>();
    Result = GameObject.Find("ResultText").GetComponent<Text>();
    Submit = GameObject.Find("Submit").GetComponent<Button>();
    Copy = GameObject.Find("Copy").GetComponent<Button>();
    Submit.onClick.AddListener(GroupSearchGroupMembersSDK);
    Copy.GetComponentInChildren<Text>().text = Utils.t("Copy");
    Copy.onClick.AddListener(CopyText);
    if (CurrentSceneInfo.info != null)
    {
      Header.text = Utils.IsCn() ? CurrentSceneInfo.info.apiText + " " + CurrentSceneInfo.info.apiName : CurrentSceneInfo.info.apiName;
      Submit.GetComponentInChildren<Text>().text = CurrentSceneInfo.info.apiName;
    }
    GetGroup();
  }

  void ToggleValueChanged(Toggle change)
  {
    string groupId = change.GetComponentInChildren<Text>().text.Split(':')[1];
    if (change.isOn)
    {
      SelectedGroups.Add(groupId);
    }
    else
    {
      SelectedGroups.Remove(groupId);
    }
  }

  void GenerateToggle(List<GroupBaseInfo> GroupList)
  {
    var Parent = GameObject.Find("ToggleContent");
    foreach (Transform child in Parent.transform)
    {
      GameObject.Destroy(child.gameObject);
    }
    var Toggler = GameObject.Find("Toggler").GetComponent<Toggle>();
    foreach (GroupBaseInfo group in GroupList)
    {
      var group_id = group.group_base_info_group_id;
      var obj = Instantiate(Toggler, Parent.transform);
      obj.GetComponentInChildren<Text>().text = "groupId:" + group_id;
      obj.isOn = false;
      obj.onValueChanged.AddListener(delegate
    {
      ToggleValueChanged(obj);
    });
    }
  }

  void SetGroupList(params object[] parameters)
  {
    try
    {
      string text = (string)parameters[1];
      print(text);
      var GroupList = Utils.FromJson<List<GroupBaseInfo>>(text);
      GenerateToggle(GroupList);
    }
    catch (Exception ex)
    {
      print(ex);
      Toast.Show(Utils.t("getGroupListFailed"));
    }
  }
  public void GetGroup()
  {
    var cb = Utils.addAsyncStringDataToScreen(SetGroupList);
    TIMResult res = TencentIMSDK.GroupGetJoinedGroupList(cb);
  }

  public void GroupSearchGroupMembersSDK()
  {
    var fieldList = new List<TIMGroupMemberSearchFieldKey>();
    if (IsSearchUserId.isOn)
    {
      fieldList.Add(TIMGroupMemberSearchFieldKey.kTIMGroupMemberSearchFieldKey_Identifier);
    }
    if (IsSearchNickName.isOn)
    {
      fieldList.Add(TIMGroupMemberSearchFieldKey.kTIMGroupMemberSearchFieldKey_NikeName);
    }
    if (IsSearchRemark.isOn)
    {
      fieldList.Add(TIMGroupMemberSearchFieldKey.kTIMGroupMemberSearchFieldKey_Remark);
    }
    if (IsSearchNameCard.isOn)
    {
      fieldList.Add(TIMGroupMemberSearchFieldKey.kTIMGroupMemberSearchFieldKey_NameCard);
    }
    var param = new GroupMemberSearchParam
    {
      group_search_member_params_groupid_list = new List<string>(SelectedGroups),
      group_search_member_params_keyword_list = new List<string>(Input.text.Split(',')),
      group_search_member_params_field_list = fieldList
    };
    TIMResult res = TencentIMSDK.GroupSearchGroupMembers(param, Utils.addAsyncStringDataToScreen(GetResult));
    Result.text = Utils.SynchronizeResult(res);
  }

  void GetResult(params object[] parameters)
  {
    Result.text += (string)parameters[0];
  }

  void CopyText()
  {
    Utils.Copy(Result.text);
  }
  void OnApplicationQuit()
  {
    TencentIMSDK.Uninit();
  }
}

results matching ""

    No results matching ""