getConversationList

Introduction

Load the list of conversations

Get the list of conversations, each item is V2TimConversation. Currently, IM SDK sorts the session list as follows:

[Version 3.8.0 and later]: Sorts with orderKey. The larger the OrderKey value, the higher the order of the conversation. The orderKey field is an integer number. When sending new messages, receiving new messages, setting a draft or pinning the conversation to the top, the conversation is activated, and the Orderkeyfield will increase.

[Versions prior to 3.8.0]: Sorts with the timeStamp of the last message. The larger the timestamp, the higher the order of the conversation.

This method requests the conversation list cached locally, while the cached list can be synchronized with the server if updates happen, and notice you with V2TimConversationListener.

The last message of a conversation can be empty in some cases, like after clear the conversation. As a result, you have better to deal with the error happened because this, in the versions prior to 3.8.0.

A locally stored conversation list can have unlimited number of conversations. A conversation list stored in the cloud can have up to 100 conversations.

If the information of a conversation has not been updated for a long time, this conversation can be stored in the cloud for at most 7 days. To adjust the period for storing the conversation, contact us.

Locally stored conversations may not always be consistent with those stored in the cloud. If you do not call the deleteConversation API to delete the local conversations, these conversations will always exist. However, at most 100 conversations can be stored in the cloud. In addition, if the information of a conversation has not been updated for a long time, this conversation can be stored in the cloud for at most 7 days. Therefore, local conversations displayed on different mobile phones may be inconsistent with each other.

Updating the conversation list

Parameter details

Parameter name Parameter type Required Platform Description
nextSeq String yes All The sequence number in this iteration requesting, it will be "0" in the first request, and request with this in the following request.
count int yes All The number of conversation items in the request for each page, while it should not be too much, which will affect the speed of requesting. It is recommended to request 100 conversations each time.

Returned template

V2TimValueCallback<V2TimConversationResult>

{
    code : int
    desc : String
    data : {
      conversationList : List<V2TimConversation>
      isFinished : bool
      nextSeq : String // the sequence number for the next request.
    }
}

Return value details

name type description
code int Request result: Error codes. 0 means success.
desc String The description of the error. It will be empty if success.
data V2TimConversationResult The list of conversations.

Code example

    V2TimValueCallback<V2TimConversationResult> getConversationListRes =
        await TencentImSDKPlugin.v2TIMManager
            .getConversationManager()
            .getConversationList(
            count: 100, 
            nextSeq: "0"
            );
    if (getConversationListRes.code == 0) {
      bool? isFinished = getConversationListRes.data?.isFinished;
      String? nextSeq = getConversationListRes.data?.nextSeq;
      List<V2TimConversation?>? conversationList =
          getConversationListRes.data?.conversationList;
      if (!isFinished!) {
        V2TimValueCallback<V2TimConversationResult> nextConversationListRes =
            await TencentImSDKPlugin.v2TIMManager
                .getConversationManager()
                .getConversationList(count: 100, nextSeq: nextSeq = "0");
      }
      getConversationListRes.data?.conversationList?.forEach((element) {
        element?.conversationID;
        element?.draftText;
        element?.draftTimestamp;
        element?.faceUrl;
        element?.groupAtInfoList;
        element?.groupID;
        element?.groupType;
        element?.isPinned;
        element?.lastMessage;
        element?.orderkey;
        element?.recvOpt;
        element?.showName;
        element?.type;
        element?.unreadCount;
        element?.userID;
      });
    }

results matching ""

    No results matching ""