Browse SDKs · WASM
SDKsWASM

Get the conversation list

Page through the current user’s conversation list with the WASM SDK.

Copy

The conversation list belongs to the signed-in user. Each ConversationItem contains state such as the conversation identifier, unread count, latest message, pinning, and draft. Use the paginated API instead of loading the entire list at once.

Get conversations by page

Use getConversationListSplit() to page through conversations. offset is the starting position and count is the page size. The first page must start with offset: 0.

Parameters

ParameterTypeRequiredDescription
offsetnumberYesStarting offset. Pass 0 for the first page.
countnumberYesNumber of conversations to read.
const pageSize = 50;

async function loadConversationPage(offset = 0) {
  const { data } = await openimsdk.getConversationListSplit(
    { offset, count: pageSize }
  );

  mergeConversations(data);
  return data;
}

After the Promise succeeds, data contains the current page of ConversationItem[].

Conversation fields

ConversationItem includes the chat target, list display data, and the current account's conversation settings:

FieldTypeDescription
conversationIDstringStable conversation ID and the merge key for lists and events.
conversationTypeSessionTypeConversation type, such as one-to-one or group chat.
userIDstringThe other user's ID in a one-to-one chat; normally empty in a group chat.
groupIDstringThe group ID in a group chat; normally empty in a one-to-one chat.
showNamestringSnapshot of the conversation's display name.
faceURLstringSnapshot of the conversation's display avatar.
latestMsgstringSerialized content of the latest message. An empty value means that no latest message is available for display.
latestMsgSendTimenumberSend time of the latest message, used for list ordering.
unreadCountnumberNumber of messages unread by the current account in this conversation.
recvMsgOptMessageReceiveOptTypeMessage reception and notification behavior for this conversation.
groupAtTypeGroupAtTypeMention reminder state in a group chat; not used for one-to-one chats.
draftTextstringConversation draft stored on the current device.
draftTextTimenumberTime when the draft was updated.
isPinnedbooleanWhether the conversation is pinned.
isMarkedbooleanWhether the conversation is marked. This works with the “Marked” conversation group.
isPrivateChatbooleanWhether burn after reading is enabled for the private chat.
burnDurationnumberBurn-after-reading duration for the private chat.
isMsgDestructbooleanWhether scheduled server-message deletion is enabled.
msgDestructTimenumberScheduled deletion interval for server messages.
isNotInGroupbooleanWhether the current account is no longer in the group.
remarkstring (optional)Conversation remark.
attachedInfostringSDK attachment data. Parse it only according to a confirmed application contract.
exstring (optional)Conversation extension string.

Use showName and faceURL directly for list titles and avatars, but reconcile friend or group profile changes through the data and events in their respective domains. Never derive a conversation ID from the display name.

To load more, advance offset by the number of items requested. Merge results by conversationID to prevent a conversation from appearing twice when it is present in both a query result and an event.

When fewer than count items are returned, the list has reached its end. On a manual refresh, clear previous pagination state and start again from offset: 0. After signing in again, conversation events synchronize subsequent changes.

Keep the list synchronized

After getConversationListSplit() succeeds, merge the returned ConversationItem[] into the current paginated snapshot. The query itself does not trigger conversation events. While the list is open, listen for CbEvents.OnNewConversation and CbEvents.OnConversationChanged. Both events carry ConversationItem[] in data; merge new and changed conversations by conversationID.

import { CbEvents } from '@openim/wasm-client-sdk';

const handleNewConversation = ({ data }) => {
  mergeConversations(data);
};

const handleConversationChanged = ({ data }) => {
  mergeConversations(data);
};

openimsdk.on(CbEvents.OnNewConversation, handleNewConversation);
openimsdk.on(CbEvents.OnConversationChanged, handleConversationChanged);

function removeConversationListListeners() {
  openimsdk.off(CbEvents.OnNewConversation, handleNewConversation);
  openimsdk.off(CbEvents.OnConversationChanged, handleConversationChanged);
}

Call removeConversationListListeners() when the component unmounts, the user signs out, or the account changes. Track the total unread count owns the total unread count, while Report typing status owns typing state.

Do not use the joined-group list as a substitute for the conversation list. A user can belong to a group without a corresponding conversation, or retain a historical conversation after leaving the group.