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:

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.'

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.

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 Description
nextSeq string yes The sequence number in this iteration requesting, it will be "0" in the first request, and request with this in the following request.
count number yes 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<{
        nextSeq?: string;
        isFinished?: boolean;
        conversationList?: V2TimConversation[];
    }>

{
    code : number
    desc : string
    data : {
      conversationList : V2TimConversation[]
      isFinished : boolean
      nextSeq : string // the sequence number for the next request.
    }
}

Return value details

name type description
code number Request result: Error codes. 0 means success.
desc string The description of the error. It will be empty if success.
data { nextSeq?: string; isFinished?: boolean; conversationList?: V2TimConversation[]; } The list of conversations.

Code example

import { TencentImSDKPlugin } from 'react-native-tim-js';


const getConversationListRes = await TencentImSDKPlugin.v2TIMManager
    .getConversationManager()
    .getConversationList(
        100,
        '0'
    );
if (getConversationListRes.code === 0) {

    const isFinished = getConversationListRes.data?.isFinished;
    const nextSeq = getConversationListRes.data?.nextSeq;
    getConversationListRes.data?.conversationList;

    if (!isFinished!) {
        await TencentImSDKPlugin.v2TIMManager
            .getConversationManager()
            .getConversationList(100, 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 ""