Browse SDKs · WASM
SDKsWASM

Load message history

Retrieve conversation history page by page with the WASM SDK.

Copy

When a chat view opens a conversation, call getAdvancedHistoryMessageList() to establish the first-page snapshot. To load earlier messages, use the current oldest message's clientMsgID as the cursor for the next page.

Parameters

ParameterTypeRequiredDescription
conversationIDstringYesID of the conversation whose history to retrieve.
startClientMsgIDstringYesMessage ID used as the pagination anchor. Pass an empty string for the first page.
countnumberYesMaximum number of messages to retrieve.
viewTypeViewTypeYesMessage viewing direction. Use ViewType.History when loading history.
import { ViewType } from '@openim/wasm-client-sdk';

const { data: page } = await openimsdk.getAdvancedHistoryMessageList({
  conversationID,
  startClientMsgID: oldestMessage?.clientMsgID ?? '',
  count: 30,
  viewType: ViewType.History,
});

prependMessages(page.messageList);

Return result

When the Promise resolves, data is an AdvancedGetMessageResult:

FieldTypeDescription
messageListMessageItem[]Messages in the current page. See Message overview for message fields.
isEndbooleanWhether the query has reached the history boundary in the current loading direction.
errCodenumberStatus code carried by this history query result.
errMsgstringStatus description corresponding to errCode.

Merge messageList only when errCode indicates success. If the call's Promise is rejected, handle it through the standard error flow. Scope the list by conversationID and deduplicate by clientMsgID. This query does not trigger a new-message event.