GroupDecreaseGroupCounter

功能介绍

递减群计数器

该计数器的 key 如果存在,则直接在当前值的基础上根据传入的 group_counter_value 作递减操作;反之,添加 key,并在默认值为 0 的基础上根据传入的 group_counter_value 作递减操作

除了社群和话题,群计数器支持所有的群组类型。

参数详解

重载1

参数名称 参数类型 是否必填 描述
group_id string 群ID
group_counter_key string 群计数器的 key
group_counter_value ulong 群计数器的递减变化量 value
callback ValueCallback < List < GroupCounter > > 异步回调

重载2

参数名称 参数类型 是否必填 描述
group_id string 群ID
group_counter_key string 群计数器的 key
group_counter_value ulong 群计数器的递减变化量 value
callback ValueCallback< string > 异步回调 返回值的json_param的格式为string

返回模板

TIMResult

调用成功后回调函数参数:
code:int
desc:string
json_param:List<GroupCounter>
user_data:string

返回值详解

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

代码示例

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 GroupDecreaseGroupCounter : 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(GroupDecreaseGroupCounterSDK);
    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 GroupDecreaseGroupCounterSDK()
  {
    if (groupIDList.Count < 1) return;
    string group_id = groupIDList[SelectedGroup.value];

    TIMResult res = TencentIMSDK.GroupDecreaseGroupCounter(group_id, GroupCounterKey.text, Convert.ToUInt64(GroupCounterValue.text), 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 ""