Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Retrieve conversation list

Paginate conversations for the signed-in user and listen for real-time conversation updates.

Copy

Use the paginated conversation API to build the current user's conversation list; do not use unpaginated full-list retrieval.

Code example

import sdk, {
  EventOnConversationChangedData,
  EventOnNewConversationData,
  GetConversationListSplitReq,
  GetConversationListSplitResp,
  OpenIMSDKEvent,
} from '@openimsdk/imsdk';

const request: GetConversationListSplitReq = {
  pagination: {
    pageNumber: 1,
    showNumber: 50,
  },
};
const response: GetConversationListSplitResp = await sdk.getConversationListSplit(request);
mergeConversations(response.conversationList);

const handleNewConversation = (data: EventOnNewConversationData): void => {
  mergeConversations(data.conversationList);
};
const handleConversationChanged = (data: EventOnConversationChangedData): void => {
  mergeConversations(data.conversationList);
};
const unsubscribeNew = sdk.on(OpenIMSDKEvent.EventOnNewConversation, handleNewConversation);
const unsubscribeChanged = sdk.on(
  OpenIMSDKEvent.EventOnConversationChanged,
  handleConversationChanged,
);

export function removeConversationListListeners(): void {
  unsubscribeNew();
  unsubscribeChanged();
}

Parameters

ParameterTypeRequiredDescription
pagination.pageNumbernumberYesPage index, starting from 1.
pagination.showNumbernumberYesNumber of conversations to fetch per page.

Return value

Returns a Promise that resolves to a GetConversationListSplitResp object containing conversationList: IMConversation[]. Deduplicate and merge items using conversationID:

PropertyTypeDescription
conversationIDstringUnique conversation ID, also used as the incremental merge key.
conversationTypeSessionTypeConversation category (Single or WriteGroup).
userID, groupIDstringPeer user ID or group ID according to the conversation type.
showName, faceURLstringDisplay title and avatar URL for the conversation.
recvMsgOptConvRecvMsgOptMessage notification delivery preference.
unreadCountnumberCurrent unread message badge count.
groupAtTypeConvGroupAtTypeGroup mention notification flag.
latestMsgIMMessageLatest message summary object.
latestMsgSendTimenumberUnix timestamp in milliseconds of the latest message.
draftText, draftTextTimestring, numberDraft content string and draft save timestamp.
isPinnedbooleanWhether the conversation is pinned to the top.
isPrivateChatbooleanWhether burn-after-reading mode is enabled.
burnDurationnumberBurn-after-reading countdown duration in seconds.
isMsgDestructbooleanWhether periodic message destruction is enabled on the server.
msgDestructTimenumberServer retention window in seconds before destruction.
remarkstringUser-specific remark note for this conversation.
isMarkedbooleanWhether this conversation is flagged.
exstringCustom metadata extension string.

State changes after the call

Detach listeners using removeConversationListListeners() when signing out or unmounting the conversation list view. Receiving an incremental change event does not guarantee that previous unread pagination pages are complete; after reconnection or synchronization completes, re-query starting from page 1 to calibrate local view state.