SDKsWASM
Load message history
Retrieve conversation history page by page with the WASM SDK.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | ID of the conversation whose history to retrieve. |
startClientMsgID | string | Yes | Message ID used as the pagination anchor. Pass an empty string for the first page. |
count | number | Yes | Maximum number of messages to retrieve. |
viewType | ViewType | Yes | Message 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:
| Field | Type | Description |
|---|---|---|
messageList | MessageItem[] | Messages in the current page. See Message overview for message fields. |
isEnd | boolean | Whether the query has reached the history boundary in the current loading direction. |
errCode | number | Status code carried by this history query result. |
errMsg | string | Status 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.
Was this page helpful?