GroupSetGroupCounters

introduction

Set Group Counters

If the key of the counter exists, the value of the counter is updated directly; if not, the key-value of the counter is added.

When the group counter is successfully set, the information about the final successfully set group counter is returned in the succ callback.

Group counters support all group types except for communities and topics.

Parameter details

overload1

Parameter name Parameter type Required Description
group_id string Required Group ID
group_counter_array List< GroupCounter > Required Group Counter Array
callback ValueCallback < List < GroupCounter > > Required Asynchronous callback.

overload2

Parameter name Parameter type Required Description
group_id string Required Group ID
group_counter_array List< GroupCounter > Required Group Counter Array
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:List<GroupCounter>
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.
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 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 EasyUI.Toast;
using System.Collections;
using System.Text;
using System.Collections.Generic;
public class GroupSetGroupCounters : MonoBehaviour
{
  string[] Labels = new string[] { "SelectGroupLabel", "GroupCounterKeyLabel", "GroupCounterValueLabel" };
  public Text Header;
  public Dropdown SelectedGroup;
  public InputField GroupCounterKey;
  public InputField GroupCounterValue;
  public Text Result;
  public Button Submit;
  public Button Copy;
  List<string> groupIDList;
  void Start()
  {
    foreach (string label in Labels)
    {
      GameObject.Find(label).GetComponent<Text>().text = Utils.t(label);
    }
    Header = GameObject.Find("HeaderText").GetComponent<Text>();
    SelectedGroup = GameObject.Find("GroupID").GetComponent<Dropdown>();
    GroupCounterKey = GameObject.Find("GroupCounterKey").GetComponent<InputField>();
    GroupCounterValue = GameObject.Find("GroupCounterValue").GetComponent<InputField>();
    Result = GameObject.Find("ResultText").GetComponent<Text>();
    Submit = GameObject.Find("Submit").GetComponent<Button>();
    Copy = GameObject.Find("Copy").GetComponent<Button>();
    Submit.onClick.AddListener(GroupSetGroupCountersSDK);
    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;
    }
    GroupGetJoinedGroupListSDK();
  }

  void GetGroupList(params object[] parameters)
  {
    try
    {
      groupIDList = new List<string>();
      SelectedGroup.ClearOptions();
      string text = (string)parameters[1];
      List<GroupBaseInfo> List = Utils.FromJson<List<GroupBaseInfo>>(text);
      foreach (GroupBaseInfo item in List)
      {
        print(item.group_base_info_group_id);
        groupIDList.Add(item.group_base_info_group_id);
        Dropdown.OptionData option = new Dropdown.OptionData();
        option.text = item.group_base_info_group_id;
        SelectedGroup.options.Add(option);
      }
      if (List.Count > 0)
      {
        SelectedGroup.captionText.text = List[SelectedGroup.value].group_base_info_group_id;
      }
      else
      {
        SelectedGroup.captionText.text = "";
      }
    }
    catch (Exception ex)
    {
      Toast.Show(Utils.t("getGroupListFailed"));
    }
  }

  void GroupGetJoinedGroupListSDK()
  {
    TIMResult res = TencentIMSDK.GroupGetJoinedGroupList(Utils.addAsyncStringDataToScreen(GetGroupList));
    print($"GroupGetJoinedGroupListSDK {res}");
  }

  void GroupSetGroupCountersSDK()
  {
    if (groupIDList.Count < 1) return;
    string group_id = groupIDList[SelectedGroup.value];
    List<GroupCounter> counterList = new List<GroupCounter>();
    string[] keys = GroupCounterKey.text.Split(',');
    string[] vals = GroupCounterValue.text.Split(',');

    for (int i = 0; i < keys.Length; i++)
    {
      if (i >= vals.Length)
      {
        break;
      }
      counterList.Add(new GroupCounter
      {
        group_counter_key = keys[i],
        group_counter_value = Convert.ToInt64(vals[i])
      });
    }

    TIMResult res = TencentIMSDK.GroupSetGroupCounters(group_id, counterList, 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 ""