ConvGetConvList

introduction

Get conversation list

Conversation list includes ConvInfo object.

This retrieves local cached conversation. If something updated on the server, SDK will synchronize automatically, and inform user in ConvEventCallback.

There is no limit on the number of locally stored conversations.

Up to 100 conversations can be stored in the cloud. To increase this limit, upgrade to the Ultimate edition. Then you can set the limit to 500 in the console:

If the information of a conversation has not been updated for a long time, the conversation can be stored in the cloud for up to seven days. To extend the conversation storage period, contact us for application.

Locally stored conversations may not always be consistent with those stored in the cloud. If the user does not call the ConvDelete API to delete the local conversations, the conversations will always exist. However, up to 100 conversations can be stored in the cloud, and if the information of a conversation has not been updated for a long time, the conversation can be stored in the cloud for up to seven days. Therefore, local conversations displayed on different terminals may differ.

Sending a message without updating the conv_last_msg

Updating the Conversation List

Parameter details

overload1

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

overload2

Parameter name Parameter type Required Description
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:
'[
  {
      "conv_active_time" : 1551269275,
      "conv_id" : "user2",
      "conv_is_has_draft" : false,
      "conv_is_has_lastmsg" : true,
      "conv_last_msg" : {
        "message_client_time" : 1551235066,
        "message_conv_id" : "user2",
        "message_conv_type" : 1,
        "message_elem_array" : [
            {
              "elem_type" : 0,
              "text_elem_content" : "ccccccccccccccccc"
            }
        ],
        "message_is_from_self" : true,
        "message_is_read" : true,
        "message_rand" : 1073033786,
        "message_sender" : "user1",
        "message_seq" : 16373,
        "message_server_time" : 1551235067,
        "message_status" : 2
      },
      "conv_owner" : "",
      "conv_type" : 1,
      "conv_unread_num" : 0
  }
]'// For the meaning of Json Key, please refer to ConvInfo
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 ConvInfo
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 com.tencent.im.unity.demo.utils;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class ConvGetConvList : MonoBehaviour
{
  public Text Header;
  public Text Result;
  public Button Submit;
  public Button Copy;
  public List<string> ResultText;
  private string Data;

  void Start()
  {
    Result = GameObject.Find("ResultText").GetComponent<Text>();
    Header = GameObject.Find("HeaderText").GetComponent<Text>();
    Submit = GameObject.Find("Submit").GetComponent<Button>();
    if (CurrentSceneInfo.info != null)
    {
      Header.text = Utils.IsCn() ? CurrentSceneInfo.info.apiText + " " + CurrentSceneInfo.info.apiName : CurrentSceneInfo.info.apiName;
      Submit.GetComponentInChildren<Text>().text = CurrentSceneInfo.info.apiName;
    }
    Copy = GameObject.Find("Copy").GetComponent<Button>();
    Copy.GetComponentInChildren<Text>().text = Utils.t("Copy");
    Submit.onClick.AddListener(ConvGetConvListSDK);
    Copy.onClick.AddListener(CopyText);
  }
  void ConvGetConvListSDK()
  {
    var Parent = GameObject.Find("ResultPanel");
    foreach (Transform child in Parent.transform)
    {
      GameObject.Destroy(child.gameObject);
    }
    Result = Instantiate(Result, Parent.transform);
    Result.enabled = true;
    TIMResult res = TencentIMSDK.ConvGetConvList(Utils.addAsyncStringDataToScreen(GetResult));
    Result.text = Utils.SynchronizeResult(res);
  }

  void GenerateResultText()
  {
    var Parent = GameObject.Find("ResultPanel");
    foreach (string resultText in ResultText)
    {
      var obj = Instantiate(Result, Parent.transform);
      obj.text = resultText;
    }
  }

  void GetResult(params object[] parameters)
  {
    ResultText = new List<string>();
    // ArgumentException: Mesh can not have more than 65000 vertices
    // Deal with a single Text cannot render too many words issue
    string CallbackData = (string)parameters[0];
    string[] DataList = CallbackData.Split('\n');
    int count = 0;
    while (count < DataList.Length)
    {
      // Every 400 lines render a new Text
      int end = count + 400;
      if (end > DataList.Length)
      {
        end = DataList.Length;
      }
      string[] textList = DataList.Skip(count).Take(end - count).ToArray();
      ResultText.Add(string.Join("\n", textList));
      count = end;
    }
    Data = (string)parameters[0];
    GenerateResultText();
  }

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

results matching ""

    No results matching ""