GroupSearchGroupMembers

introduction

Search group members

Only locally stored group members can be searched for, such as the list of group members or group member profiles that have been pulled.

It searches members in specified groups that match the keywordList's keyword in specified group info fields (namecard, nickname, remark, userID). Maximum number of keyword is 5.

If cannot search for the members, please invoke GroupGetMemberInfoList to store the members into local storage. Then search again.

This feature cannot be used for audio-video groups (AVChatRoom) as the group members are not stored locally.

If group_search_member_params_groupid_list is left empty, members in all the groups will be searched for and returned by groupID.

If group_search_member_params_groupid_list is not left empty, members in the specified group will be searched for.

Parameter details

overload1

Parameter name Parameter type Required Description
json_group_search_group_members_param GroupMemberSearchParam Required GroupMemberSearchParam
callback ValueCallback< List< GroupGetOnlineMemberCountResult > > Required Asynchronous callback The format of json_param in the return value is json

overload2

Parameter name Parameter type Required Description
json_group_search_group_members_param GroupMemberSearchParam Required GroupMemberSearchParam
callback ValueCallback< string > Required Asynchronous callback The format of json_param in the return value is string

Returned template

TIMResult

The parameters of the callback function after successfully calling the API:
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
  }]
}]' // For the meaning of Json Key, please refer to [GroupGetOnlineMemberCountResult]
user_data:string

Return value details

name type description
TIMResult TIMResult Return value of calling API
code int Result error code: Error Codes
desc string The description of the error.
json_param string Json string. Calling different API will get different Json strings. For the meaning of Json Key, please refer to GroupGetOnlineMemberCountResult
user_data string User-defined data transfered by ImSDK without any processing

Code example

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 ""