Browse SDKs · React Native
SDKsReact Native

Retrieve the conversation list

Retrieve the current user's conversation list with pagination.

Copy

Use getConversationListSplit() to retrieve the conversation list page by page.

const conversations = await OpenIMSDK.getConversationListSplit({
  offset: 0,
  count: 50,
});

Parameters

ParameterTypeRequiredDescription
offsetnumberYesPagination offset. Use 0 for the first page and increase it by the number of items already requested.
countnumberYesNumber of conversations to request.

Return result

The call returns the current page as ConversationItem[]. When fewer than count items are returned, the current list has reached its end.

Conversation fields

ConversationItem contains the chat target, list presentation data, and settings for the current account:

FieldTypeDescription
conversationIDstringConversation ID.
conversationTypeSessionTypeConversation type, such as one-to-one or group.
userIDstringThe other user's ID in a one-to-one conversation; usually empty for group conversations.
groupIDstringGroup ID for a group conversation; usually empty for one-to-one conversations.
showNamestringDisplay name of the conversation.
faceURLstringDisplay avatar URL of the conversation.
recvMsgOptMessageReceiveOptTypeMessage reception setting for the conversation.
unreadCountnumberNumber of unread messages in the conversation.
groupAtTypeGroupAtTypeMention status for a group conversation; not used for one-to-one conversations.
latestMsgstringJSON-serialized content of the latest message.
latestMsgSendTimenumberTime when the latest message was sent.
draftTextstringDraft saved on the current device.
draftTextTimenumberTime when the draft was updated.
isPrivateChatbooleanWhether burn-after-reading is enabled for the one-to-one conversation.
burnDurationnumberBurn-after-reading duration for the one-to-one conversation.
isMsgDestructbooleanWhether scheduled server-side message deletion is enabled.
msgDestructTimenumberServer-side message deletion period.
isPinnedbooleanWhether the conversation is pinned.
isMarked EnterprisebooleanWhether the conversation is marked.
isNotInGroupbooleanWhether the current account is no longer in the group.
attachedInfostringAdditional information attached by the SDK.
exstring (optional)Conversation extension string.
remark Enterprisestring (optional)Conversation remark.

When loading multiple pages, deduplicate them by conversationID. Start again from offset: 0 when refreshing the list.

Listen for conversation changes

OnNewConversation is emitted when a conversation is created. OnConversationChanged is emitted when an existing conversation changes. Both callbacks receive ConversationItem[].

function handleNewConversation(conversations: ConversationItem[]) {
  // ...
}

function handleConversationChanged(conversations: ConversationItem[]) {
  // ...
}

OpenIMSDK.on(OpenIMEvent.OnNewConversation, handleNewConversation);
OpenIMSDK.on(OpenIMEvent.OnConversationChanged, handleConversationChanged);

OpenIMSDK.off(OpenIMEvent.OnNewConversation, handleNewConversation);
OpenIMSDK.off(OpenIMEvent.OnConversationChanged, handleConversationChanged);

Remove the listeners when logging out, switching accounts, or tearing down the conversation-list state.