ConvPinConversation

introduction

Pin conversation

The new SDK version has added the pinConversation API to pin/unpin conversations to/from the top. It also supports roaming and multi-client synchronization.

If you call SetConvEventCallback in advance to add a conversation listener, you can get the ConvInfo object in the callback.

The ConvInfo conversation object has added the conv_is_pinned field, which is used to determine whether a conversation is pinned on top.

Call ConvGetConvList to retrieve the list of conversation. It'll return pinned conversation then unpinned conversation. You can check ConvInfo object's conv_is_pinned.

Pinned conversation lines before the unpinned ones. But it doesn't affect the inner sequence. Eg. 5 conversation is sequence are 1,2,3,4,5 and you pin 2 and 3 then the sequence becomes 2,3,1,4,5. Appearently 2 and 3 are at the front, and 2 is before 3.

The sequence of conversation is lined by ConvInfo object's conv_active_time.

Parameter details

overload1

Parameter name Parameter type Required Description
conv_id string Required Conversation ID
conv_type TIMConvType Required Conversation type
is_pinned bool Required Is pinned
callback NullValueCallback Required Asynchronous callback

overload2

Parameter name Parameter type Required Description
conv_id string Required Conversation ID
conv_type TIMConvType Required Conversation type
is_pinned bool Required Is pinned
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:'' // json_ Params is an empty string ""
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.Collections.Generic;
public class ConvPinConversation : MonoBehaviour
{
  public Text Header;
  public Dropdown SelectedConv;
  public Text Result;
  public Button Submit;
  public Button Copy;
  public Toggle PinToggle;
  private List<ConvInfo> ConvList;
  void Start()
  {
    GameObject.Find("SelectConvLabel").GetComponent<Text>().text = Utils.t("SelectConvLabel");
    GameObject.Find("PinLabel").GetComponent<Text>().text = Utils.t("PinLabel");
    ConvGetConvListSDK();
    PinToggle = GameObject.Find("Toggle").GetComponent<Toggle>();
    Header = GameObject.Find("HeaderText").GetComponent<Text>();
    SelectedConv = GameObject.Find("Dropdown").GetComponent<Dropdown>();
    Result = GameObject.Find("ResultText").GetComponent<Text>();
    Submit = GameObject.Find("Submit").GetComponent<Button>();
    Copy = GameObject.Find("Copy").GetComponent<Button>();
    Copy.GetComponentInChildren<Text>().text = Utils.t("Copy");
    Submit.onClick.AddListener(ConvPinConversationSDK);
    Copy.onClick.AddListener(CopyText);
    SelectedConv.interactable = true;
    if (CurrentSceneInfo.info != null)
    {
      Header.text = Utils.IsCn() ? CurrentSceneInfo.info.apiText + " " + CurrentSceneInfo.info.apiName : CurrentSceneInfo.info.apiName;
      Submit.GetComponentInChildren<Text>().text = CurrentSceneInfo.info.apiName;
    }
  }

  void GetConvList(params object[] parameters)
  {
    try
    {
      ConvList = new List<ConvInfo>();
      SelectedConv.ClearOptions();
      string text = (string)parameters[1];
      List<ConvInfo> List = Utils.FromJson<List<ConvInfo>>(text);
      foreach (ConvInfo item in List)
      {
        print(item.conv_id);
        ConvList.Add(item);
        Dropdown.OptionData option = new Dropdown.OptionData();
        option.text = item.conv_id;
        SelectedConv.options.Add(option);
      }
      if (List.Count > 0)
      {
        SelectedConv.captionText.text = List[SelectedConv.value].conv_id;
      }
    }
    catch (Exception ex)
    {
      Toast.Show(Utils.t("getConvListFailed"));
    }
  }

  void ConvGetConvListSDK()
  {
    TIMResult res = TencentIMSDK.ConvGetConvList(Utils.addAsyncStringDataToScreen(GetConvList));
    print($"ConvGetConvListSDK {res}");
  }

  void ConvPinConversationSDK()
  {
    print(ConvList[SelectedConv.value].conv_id);
    string conv_id = ConvList[SelectedConv.value].conv_id;
    TIMConvType conv_type = ConvList[SelectedConv.value].conv_type;
    TIMResult res = TencentIMSDK.ConvPinConversation(conv_id, conv_type, PinToggle.isOn, Utils.addAsyncNullDataToScreen(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 ""